如何在 Tomcat 6 中禁用传输编码 [英] How do disable Transfer-Encoding in Tomcat 6

查看:24
本文介绍了如何在 Tomcat 6 中禁用传输编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Tomcat 6.0.29 服务器和 JDK 1.6 上运行的 Web 应用程序.

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

当我向客户端发送响应时,Tomcat 发送

When I send the response to the client, Tomcat sends

Transfer-Encoding: chunked 

当响应大小 > 8KB 时在标头中.对于响应 <8KB,它发送

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

如何在 Tomcat 中禁用分块编码?

How can I disable Chunked encoding in Tomcat?

我可以在 Tomcat 中禁用 HTTP/1.1 并启用 HTTP/1.0(不知道该怎么做)

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. server.xml 的 Connector 标签中,我设置了 bufferSize ="65536"

  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;

  • 在 server.xml 中使用 NIOConnector,配置如下:

  • 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" />
    

  • 推荐答案

    我可以让它工作的唯一方法是在响应中设置 BufferSize.

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

    response.setBufferSize() 设置响应大小的 Content-Length 标头.一旦响应大小超过 bufferSize,它将回退到 Transfer-Encoding: Chunked.缓冲区大小应设置为适当的值.将其设置为更高的值将在刷新之前缓冲内存中的所有响应.所以这个值应该设置为一个乐观的大小.

    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.

    我的客户很少依赖 Content-Length 响应标头.我必须设置它以实现向后兼容性.默认情况下,Tomcat 缓冲区大小设置为 8K(我认为对于 Weblogic/Websphere,这是 32K 字节).

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

    这篇关于如何在 Tomcat 6 中禁用传输编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆