Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 838
Carlos AG Avatar asked Dec 19 '22 23:12

Carlos AG


1 Answers

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).

like image 160
Nikos Paraskevopoulos Avatar answered Dec 24 '22 02:12

Nikos Paraskevopoulos