tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Óscar Frías Barranco <>
Subject Chunked encoding should be used also when not using keepalive
Date Thu, 01 Apr 2010 10:02:24 GMT

Currently Tomcat HTTP 1.1 Connector disables the use of chunked encoding if
keepalive is not used.  This happens when an HTTP 1.1 request contains a
"Connection: close" header.
I propose to change Coyote to use chunked encoding (for HTTP 1.1) even if
keepalive is disabled.

Chunked transfer-encoding is an alternative to content-length, for use when
the content-length cannot initially be determined.  While it is mandatory to
have either of them to support keep-alive, its use is not restricted to
keep-alive and one useful immediate benefit of using it is to allow a client
to distinguish a connection abort from a complete response in order to avoid
storing truncated data.

Another useful case is when a reverse-proxy is installed in front of the
server, and this reverse proxy tries to maintain keep-alive connections with
the clients and intends to close the connections with the servers (like
apache 1.3, haproxy, and I think nginx).  The lack of content-length and
chunked encoding prevents the proxy from keeping client connections alive.
The "connection: close" sent by the proxy to the server only indicates that
the proxy will send just one request to the server, not that it does not
care about the response length.  The same is true when that proxy caches.
Without any content-length nor chunked encoding, the cache could store and
distribute truncated response believing they are complete, while this would
not happen with chunked encoding because the cache will be able to know it
has not seen the end of the response.

The fix seems easy.  This is the patch:

Index: java/org/apache/coyote/http11/
--- java/org/apache/coyote/http11/    Tue Mar 09
18:09:50 CET 2010
+++ java/org/apache/coyote/http11/    Tue Mar 09
18:09:50 CET 2010
@@ -1547,7 +1547,7 @@
             contentDelimitation = true;
         } else {
-            if (entityBody && http11 && keepAlive) {
+            if (entityBody && http11) {
                 contentDelimitation = true;

What do you think ?

Oscar Frias

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message