0

Background

For server to server communication we are hashing request/response payloads with a shared key and storing the hash in a http header.

Issue

We are running into an issue with a controller returning a large payload (base64 string of a pdf doc) and the http header containing the hash is not being written to the response. This appears to be due to exceeding the size limit of 8KB (8192). See this post for more information on the size limit for Tomcat 7: Is there a practical HTTP Header length limit?

Solution Tried

  1. I tried setting the following tomcat settings which did not have an effect:

       maxHttpHeaderSize="16384" 
       maxTrailerSize="-1" 
       maxExtensionSize="-1" 
       socket.appReadBufSize="16384"   
       socket.appWriteBufSize="16384"   
       bufferSize="16384"
    
  2. I can set the response buffer size to something greater than 8192 in the controller I do see the hash value http header written to the response. The problem with this solution is the response buffer size is set for subsequent responses that use the same thread. If you try to set the buffer size back to 8192 you will get an exception : "Cannot change buffer size after data has been written"

    class TestController { def index() { response.setBufferSize( 9216 ) def size = 8193 render "A" * size } }

enter image description here

System Information

Grails 2.5.2
Tomcat 7
Java 1.8 Build 66
Windows 7 Enterprise 64 bit

https://tomcat.apache.org/tomcat-7.0-doc/config/http.html

Questions

  1. Has anyone been able to use the tomcat settings in server.xml to solve this problem?
  2. Is there a point in the request life cycle that the response buffer size can be returned to the default size?
  3. Should I worry about setting the buffer size back? Does the buffer size affect memory consumption?
Community
  • 1
  • 1
  • A hash value is larger than 8k? Somehow I find that hard to believe. Did you check that it's not by acident the PDF being written into the *header* instead of the response body? – Jan Dec 13 '15 at 13:45
  • It's not the size of the header. The header I believe is only 44 bytes. Tomcat appears to be taking the size of the payload into account. The header is not written because the 44 bytes will not fit. – Mitch McKenzie Dec 14 '15 at 15:31
  • If the header is below 8k then that message doesn't make any sense at all - can you provide working example / more code to check? I did servlet-generated PDF downloads before without issues – Jan Dec 14 '15 at 15:36

0 Answers0