Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do disable Transfer-Encoding in Tomcat 6

I have a web application running on Tomcat 6.0.29 server and JDK 1.6.

When I send the response to the client, Tomcat sends

Transfer-Encoding: chunked 

in the headers when the response size is > 8KB. For responses < 8KB, it sends

Content-Length : 

I understand that Chunked encoding is the preferred way to handle bulk responses, however our clients do not want to change their code (as it is distributed all across the servers).

How can I disable Chunked encoding in Tomcat?

I could Disable HTTP/1.1 in Tomcat and enable HTTP/1.0 (not sure how I can do this)

I tried the following with no success:

  1. In Connector tag in server.xml, I set bufferSize =" 65536"

    Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           bufferSize="65536" socketBuffer="65536"
           redirectPort="8443" /&gt;
    
  2. Using NIOConnector in server.xml with following configuration:

    <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
           connectionTimeout="20000"
           socket.directBuffer="false"
           socket.rxBufSize="25188"
           socket.txBufSize="43800"
           socket.appReadBufSize="32768"
           socket.appWriteBufSize="32768"
           socket.bufferPool="500"
           socket.bufferPoolSize="100000000"
           socket.processorCache="500"
           socket.keyCache="500"
           socket.eventCache="500"
           socket.tcpNoDelay="false"
           socket.soKeepAlive="true"
           socket.soTimeout="5000"
           redirectPort="8443" />
    
like image 879
Rajendra Avatar asked Jun 09 '11 21:06

Rajendra


People also ask

How do you stop transfer encoding chunked?

Try adding "&headers=false" to your request. That should shorten it up and cause the response to be less likely to be chunked. Also, are you sending a HTTP/1.1 or HTTP/1.0 request? Try sending a HTTP/1.0 if your device cannot handle a HTTP/1.1 request.

What does Transfer Encoding do?

Transfer-Encoding is a hop-by-hop header, that is applied to a message between two nodes, not to a resource itself. Each segment of a multi-node connection can use different Transfer-Encoding values. If you want to compress data over the whole connection, use the end-to-end Content-Encoding header instead.


2 Answers

The only way I could get it working is by setting the BufferSize on response.

response.setBufferSize() sets the Content-Length header of the response size. Once the response size goes beyond the bufferSize it would fallback to Transfer-Encoding: Chunked. The buffer size should be set to an appropriate value. Setting it to a higher value would buffer all of the response in memory before flushing it. So the value should be set to an optimistic size.

Few of my clients are depending on Content-Length response header. I have to set this for backward compatibility. By default Tomcat buffer size is set to 8K (I think for Weblogic/Websphere this is 32K bytes).

like image 153
Rajendra Avatar answered Oct 07 '22 02:10

Rajendra


As far as I know, to disable chunked output in Tomcat you must supply a content length header in your servlet.

like image 22
Paul Gregoire Avatar answered Oct 07 '22 00:10

Paul Gregoire