Thank you. 

Can you suggest a way to confirm the problem is size related? Or are you 
convinced by the numbers shown?

The client is a Java 15 app so there’s a chance I could use trailer headers. 
I’m not explicitly using chunked encoding currently. 

I don’t like the idea of buffering the entire response as this is the part of 
my setup where there are likely thousands of nearly simultaneous requests and 
the server isn’t that beefy. 

And I take it there is no mechanism in tomcat 9 to force the headers out on an 
implicit flush?  Or other mechanism which ensures headers are sent?

I may split the large ones off to a separate endpoint to give those a larger 
buffer. The datum returned in the header is very much tied to the payload. 
Would a multi-part response make sense?  Sticking the datum into the payload 
steam would be very difficult. 

Thanks again for your insights. They are indeed helpful. 

rjs

> On Apr 12, 2021, at 2:16 AM, Mark Thomas <ma...@apache.org> wrote:
> 
> maxHttpHeaderSize only applies to Tomcat reading requests from clients. It 
> has no impact on the headers Tomcat sends to the client.
> 
> Given that the issue is size dependent and the the header is missing only on 
> the larger responses, I would guess that the Servlet is writing the header 
> after the response has been committed in those cases and is, therefore, being 
> lost.
> 
> In HTTP, headers usually come before the body. When generating a response, 
> Tomcat will buffer the response body until either there is an explicit flush 
> or explicit commit or the buffer is full at which point an implicit flush 
> occurs.
> 
> When a flush (implicit or explicit) occurs, if the response is not committed 
> at that point then the response is automatically committed. Committing the 
> response == writing the response headers.
> 
> You typically want to ensure that the Servlet writes all the headers before 
> it writes the response body.
> 
> There are alternative options:
> 1. Use a large enough response buffer to buffer the entire response. Keep in 
> mind you need to have enough free memory for every concurrent request to have 
> a buffer this large whether it uses it or not.
> 
> 2. Servlet 4 (Tomcat 9 onwards) added support for trailer headers (see RFC 
> 7230 section 4.4). These can be used with chunked encoding and allows header 
> values to be written after the response body. You might want to confirm that 
> the client you are using supports trailer headers.
> 
> HTH,
> 
> Mark
> 
> 
>> On 11/04/2021 23:53, Rob Sargent wrote:
>> I should mention that this is entirely on localhost (running linux) and 
>> using https.
>>> On 4/11/21 8:31 AM, Rob Sargent wrote:
>>> Thanks, I’ll go back to reading headers first.
>>> I did not mean to imply the header content differed significantly. The 
>>> header value is always an integer (< 100).
>>> 
>>>> On Apr 10, 2021, at 11:10 PM, Brian Wolfe <wolfebrian2...@gmail.com> wrote:
>>>> 
>>>> So i'm not too familiar with tomcat 9. However, I did notice that
>>>> maxHttpHeaderSize
>>>> default is supposed to be 8KB in 9. That is set on the connector. Which
>>>> affects both request and response headers.
>>>> 
>>>> https://tomcat.apache.org/tomcat-9.0-doc/config/http.html
>>>> 
>>>> Did you try that?
>>>> 
>>>> If i'm not mistaken about a stream of content. the response headers should
>>>> be the first thing that is received by the client. Then the body can be
>>>> split and transmitted along the connection.
>>>> 
>>>>> On Sat, Apr 10, 2021 at 10:06 PM Rob Sargent <rsarg...@xmission.com> 
>>>>> wrote:
>>>>> 
>>>>> I saw this mentioned a couple years ago, on tomcat 7, but don't see
>>>>> anything recent on this topic and I'm using 9.0.43.  Of 59 separate
>>>>> requests to same servlet three repeatedly do not have the header entry
>>>>> added by the servlet to the response.  The remaining 56 all have the
>>>>> header/value.  The three consistently lose the header.
>>>>> 
>>>>> Size matters?  The 56 which succeed are on average 203 units in payload
>>>>> size while the bad boys are 7K,10K,13K units. (And I'm guessing about
>>>>> 100 bytes per unit)
>>>>> 
>>>>> The clients streams the payload from the response, and I've tried
>>>>> getting the header both before and after the stream has been read.
>>>>> 
>>>>> Any clues as to where the missing header goes?  Does the servlet not
>>>>> send it or is it in some /other/ response?
>>>>> 
>>>>> Thanks,
>>>>> rjs
>>>>> 
>>>>> 
>>>> -- 
>>>> Thanks,
>>>> Brian Wolfe
>>>> https://www.linkedin.com/in/brian-wolfe-3136425a/
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to