ServletResponse.setBufferSize not working in Tomcat 7?

I am increasing the size of the response buffer with ServletResponse.setBufferSize, but Tomcat 7 still throws an exception that the buffer size is not large 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 an exception -

org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write more data to the response headers than there was a place in the buffer. Increase maxHttpHeaderSize on the connector or write less data in the response headers.

Do I need to reset the buffer? reset()does not work.

EDIT: I'm looking for an opportunity to change the maximum header size at the individual response level based on "some state".

+3
source share
3 answers

, . " Tomcat" " HTTP"

maxHttpHeaderSize

HTTP- , . , 8192 (8 ).

+1

HTTP- maxHttpHeaderSize server.xml, .

.

0

What are you doing

You set the buffer size for the writig repeater body. It has nothing to do with response headers. This is mainly used to discard responses after reaching the buffer size.

What you need to do

You need to set the property maxHttpHeaderSizein Tomcat Configuration

0
source

All Articles