简体   繁体   English

ServletResponse.setBufferSize在Tomcat 7中不起作用吗?

[英]ServletResponse.setBufferSize doesn't work in Tomcat 7?

I'm increasing the buffer size of a response using ServletResponse.setBufferSize but Tomcat 7 is still throwing an exception that the buffer size is not big enough. 我正在使用ServletResponse.setBufferSize增加响应的缓冲区大小,但是Tomcat 7仍然抛出一个异常,即缓冲区大小不够大。 Is this a bug in Tomcat 7.0.32? 这是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 the exception - 这是例外-

org.apache.coyote.http11.HeadersTooLargeException : An attempt was made to write more data to the response headers than there was room available in the buffer. org.apache.coyote.http11.HeadersTooLargeException :尝试将比缓冲区中可用空间更多的数据写入响应标头。 Increase maxHttpHeaderSize on the connector or write less data into the response headers. 增加连接器上的maxHttpHeaderSize或将较少的数据写入响应标头。

Do I need to reset the buffer? 我需要重置缓冲区吗? reset() did not work. reset()无效。

EDIT: I'm looking for the ability to change the maximum header size at the individual response level based upon "some condition". 编辑:我正在寻找能够基于“某些条件”在各个响应级别更改最大标头大小的功能。

The message is about header size, not total buffer size. 该消息与报头大小有关,而不是缓冲区总大小。 From the Tomcat Configuration Guide section on "The HTTP Connector" “ HTTP连接器”上的《 Tomcat配置指南》部分中

maxHttpHeaderSize maxHttpHeaderSize

The maximum size of the request and response HTTP header, specified in bytes. 请求和响应HTTP标头的最大大小,以字节为单位指定。 If not specified, this attribute is set to 8192 (8 KB). 如果未指定,则此属性设置为8192(8 KB)。

What you are doing 你在做什么

You are setting the size of the buffer for writig repsonse body. 您正在设置写回信主体的缓冲区大小。 It has nothing to do with the response headers. 它与响应头无关。 This is mainly used for flushing responses once the buffer size is reached. 一旦达到缓冲区大小,这主要用于刷新响应。

What you need to do 你需要做什么

You need to set the maxHttpHeaderSize property in Tomcat Configuration 您需要在Tomcat配置中设置maxHttpHeaderSize属性

You need to modify the HTTP connector's maxHttpHeaderSize in server.xml, not the code. 您需要在server.xml中而不是代码中修改HTTP连接器的maxHttpHeaderSize。

See here. 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM