Bug 35297 - [PATCH] Chunked transfer encoding for IIS JK/ISAPI
Summary: [PATCH] Chunked transfer encoding for IIS JK/ISAPI
Alias: None
Product: Tomcat Connectors
Classification: Unclassified
Component: Common (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2005-06-09 22:30 UTC by Tim Whittington
Modified: 2014-12-31 19:44 UTC (History)
0 users

Chunked encoding patch for JK/ISAPI (16.24 KB, patch)
2005-06-09 22:33 UTC, Tim Whittington
Details | Diff
Chunked encoding patch for JK/ISAPI (28.68 KB, patch)
2008-02-17 14:05 UTC, Tim Whittington
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Whittington 2005-06-09 22:30:32 UTC
This patch adds chunked encoding for IIS responses - i.e. Transfer-Encoding:
chunked responses for HTTP/1.1 clients - allowing IIS to maintain persistent
connections to HTTP/1.1 clients through the ISAPI redirector.

IIS hands a lot of the responsibility for HTTP protocol handling to the ISAPI
extension - Apache is sooo much nicer to deal with.
IIS will keep connections alive if there is a Content-Length specified in the
request, but won't do transfer encoding for requests that don't like Apache does.

Contents of the patch:
- Added 'enable_chunked_encoding' param (bool) to enable chunked encoding
(default is disabled)
- Modified isapi_private_data_t to track whether chunked encoding is enabled per
- Modified start_response to:
   - Detect HTTP 1.1 clients and enable chunked encoding for the response (if
the Tomcat response hasn't already precluded that)
   - Determine whether IIS should be told to keep the connection alive (IIS
makes us manage this as well if we want to have the ability to keep connections)
   - Set the Transfer-Encoding: chunked header when used
   - Use the HSE_SEND_HEADER_EX_INFO/ServerSupportFunction API to allow us to
tell IIS to keep the connections open
- Factored the WriteClient calls into a new function (for the new write())
- Added support in write() for writing a chunked encoded response chunk
- Added a flush hook for IIS (with flush_packets false) to allow the chunked
encoded terminator (the 0 chunk) to be written on response completion

I'd consider the chunked encoding experimental at the moment - we're beta
testing at the moment - which is why it's disabled by default.
We've run this against fairly complex web applications, with a mix of jsp, htm,
xml, Content-Length, no Content-Length and some Connection: close behaviour, IE,
Firefox etc.
All seems to work fine at the moment - chunked encoding isn't that complex -
though IE does get confused if there are non-chunk-encoded files in the cache.
The only reported failure is when using Fiddler with an HTTP/1.0 client, though
I suspect this is Fiddlers problem (it can't handle 1.0 to the unpatched connector).
Straight HTTP/1.0 from IE works fine.

It'd be great to get this into the codebase and have people beta test it to see
if if any problems show up.
Any problems are likely to be the result of incorrect negotiation of keep-alive
or incorrect detection of responses from Tomcat that preclude using chunked

Comment 1 Tim Whittington 2005-06-09 22:33:07 UTC
Created attachment 15357 [details]
Chunked encoding patch for JK/ISAPI

Patch against jk_isapi_plugin.c r1.49
Comment 2 Mladen Turk 2005-07-03 11:27:37 UTC
The complexity of your patch it too big to be considered as bug.
Something like that should be considered for the 1.3 branch.
The current implementation works fine for the majority of the users.
Comment 3 Tim Whittington 2005-08-14 23:42:12 UTC
I've improved this functionality a bit - mostly tweaking and adding some of the
HTTP/1.1 edge cases for enabling chunked encoding.

I won't repatch until JK 1.3 is branched, as there's no roadmap for that at the
Comment 4 Tim Whittington 2007-06-21 01:42:46 UTC
I'm still maintaining this against the head of JK for my customers, and still
waiting for JK 1.3 (two years and counting).
The IIS connector without chunked encoding is pretty much useless for high
volume sites (I've had customers completely exhaust the TCP ports on a Windows
Server because of the lack of reuse, even with the TCP params tweaked up).
Comment 5 Tim Whittington 2008-02-17 14:05:16 UTC
Created attachment 21551 [details]
Chunked encoding patch for JK/ISAPI

I've updated the patch against head following discussions with Rainer and
Mladen on the dev list.
This patch separates out all chunk encoded behaviour based on whether chunk
encoding is enabled for the redirector (in the case of response writes this is
a flag on the private date object for the request).
I've tested this on IIS 6.0 and 5.1 with chunk encoding enabled and disabled.

There are a couple of minor variances from trunk behaviour here:
- I've disabled SF_NOTIFY_AUTH_COMPLETE for IIS 5.1 (copied from my patchset),
as I've never found a 5.1 it didn't break OPTIONS/PUT etc. on.
- The basic response write code has been reworked into isapi_write_client so it
can be reused for the chunked encoding on IIS 5 (vector writes are used for 6).
Comment 6 Rainer Jung 2014-12-31 15:17:41 UTC
Chunked encoding support for the ISAPI redirector has been added in the meantime.
Comment 7 Konstantin Kolinko 2014-12-31 19:44:29 UTC
(In reply to Rainer Jung from comment #6)
> Chunked encoding support for the ISAPI redirector has been added in the
> meantime.

To be specific: it was r701029 and r704677 (and maybe others in October 2008), included in 1.2.27 onwards.