How to remove Transfer-Encoding: chunked in the HTTP response

Carlos AG picture Carlos AG · Sep 23, 2013 · Viewed 10.6k times · Source

I have made a HTTP endpoint (REST in Java, Spring Framework, Apache Tomcat), in which the HTTP response has the header "Transfer-Encoding: chunked". I don't know if it is created by the servlet or the server.

I don't want that the endpoint responses that header. Is it possible to force it so as not to send that header?

Answer

Nikos Paraskevopoulos picture Nikos Paraskevopoulos · Sep 23, 2013

This is possibly created because the response is bigger than the response buffer, so the runtime is forced to flush before the response is complete. Since headers must be sent before the response and the Content-Length header is unknown, it sets Transfer-Encoding: chunked instead.

You could set the output buffer size for the Tomcat connector: see here, attribute socketBuffer for the standard and socket.appWriteBufSize for NIO. This sets the buffer size for the entire servlet containe, probably not what you want.

You could intercept the specific URL(s) that require a bigger buffer with a servlet filter and use response.setBufferSize(NNN).