Bug 53169 - [patch] don't do chunking with Connection: close
Summary: [patch] don't do chunking with Connection: close
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: All All
: P2 minor (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-01 09:35 UTC by Philippe Marschall
Modified: 2012-06-01 05:47 UTC (History)
0 users



Attachments
patch against trunk (7.94 KB, patch)
2012-05-01 09:35 UTC, Philippe Marschall
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Marschall 2012-05-01 09:35:06 UTC
Created attachment 28702 [details]
patch against trunk

The attached patch disables chunking on if there is a Connection: close header, we're on HTTP 1.1 and there's no Content-Length header.

This helps to implement Server-Sent Events [1]. Server-Sent Event are conceptually similar to the forever streaming iframe in the sense that there's an "infinite" response from the server that always gets updated. But they're easier to use and with less issues. They are also easier to use than WebSockets if you don't need a back channel.

The specification reccoments to disable chunking. Jetty implements the same behavior, when there's a Connection: close header it doesn't do chunking.

The following discussion [2] leads me to believe that patches would be welcome. The patch comes with unit tests that verify that there is still chunking happending when there is no Connection: close header.

 [1] http://dev.w3.org/html5/eventsource/#notes
 [2] http://tomcat.10.n6.nabble.com/How-to-disable-chunked-encoding-for-the-Http11NioProtocol-connector-td2038448.html
Comment 1 Mark Thomas 2012-05-30 14:17:11 UTC
The general approach is fine although I have made a number of changes to the patch:
- The Servlets in the unit tests should exist in the test class that uses them
- There is no need use the test webapp for these unit tests
- Use more of the built-in infrastructure for making a request
- Improved the checking of the response headers 

These changes identified that the Connection: close header was being set twice. It isn't illegal but it might confuse some clients. I added some additional code to prevent this.

The change has been made to trunk and 7.0.x and will be included in 7.0.28 onwards.
Comment 2 Philippe Marschall 2012-06-01 05:47:34 UTC
Thanks for cleaning up an applying.