+1 on switching to chunked by default. I don't think the extra few bytes are a problem ( or few extra objects/cycles on server ) - at least compared with not knowing if the response was really fully sent.
Costin 2010/4/1 Óscar Frías Barranco <ofr...@trabber.com> > Hello. > > 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/Http11Processor.java > =================================================================== > --- java/org/apache/coyote/http11/Http11Processor.java Tue Mar 09 > 18:09:50 CET 2010 > +++ java/org/apache/coyote/http11/Http11Processor.java Tue Mar 09 > 18:09:50 CET 2010 > @@ -1547,7 +1547,7 @@ > (outputFilters[Constants.IDENTITY_FILTER]); > contentDelimitation = true; > } else { > - if (entityBody && http11 && keepAlive) { > + if (entityBody && http11) { > outputBuffer.addActiveFilter > (outputFilters[Constants.CHUNKED_FILTER]); > contentDelimitation = true; > > > What do you think ? > > Regards, > Oscar Frias > Trabber.com >