I'm increasing the buffer size of a response using ServletResponse.setBufferSize but Tomcat 7 is still throwing an exception that the buffer size is not big enough. Is this a bug in Tomcat 7.0.32?
Here is my pseudo/code -
@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
if (some condition)
{
((ServletServerHttpResponse)outputMessage).getServletResponse().setBufferSize(Integer.MAX_VALUE);
outputMessage.getHeaders().set("Custom-Header", gson.toJson(big payload));
}
// ...
This is the exception -
org.apache.coyote.http11.HeadersTooLargeException
: An attempt was made to write more data to the response headers than there was room available in the buffer. Increase maxHttpHeaderSize on the connector or write less data into the response headers.
Do I need to reset the buffer? reset()
did not work.
EDIT: I'm looking for the ability to change the maximum header size at the individual response level based upon "some condition".
The message is about header size, not total buffer size. From the Tomcat Configuration Guide section on "The HTTP Connector"
maxHttpHeaderSize
The maximum size of the request and response HTTP header, specified in bytes. If not specified, this attribute is set to 8192 (8 KB).
What you are doing
You are setting the size of the buffer for writig repsonse body. It has nothing to do with the response headers. This is mainly used for flushing responses once the buffer size is reached.
What you need to do
You need to set the maxHttpHeaderSize
property in Tomcat Configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With