Jetty closing sockets when contentLength != lengthOfcontentWritten

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jetty closing sockets when contentLength != lengthOfcontentWritten

Kevin Conaway
When using persistent connections, jetty will close a socket connection if the length of the content body written does not match the Content-Length header set.

This seems to be a bug in our software when we are using compression as we set the Content-Length to be the length of the uncompressed file but we are writing the compressed bytes over the wire.

I'd like to know why Jetty forces the connection to be closed though.  If anyone could shed some light on the reasoning behind this, I'd be grateful.

The relevant code is in org.mortbay.jetty.AbstractGenerator#complete()

Sincerely,

Kevin Conaway
Reply | Threaded
Open this post in threaded view
|

Re: Jetty closing sockets when contentLength != lengthOfcontentWritten

Jan Bartel
Hi Kevin,

Kevin Conaway wrote:
> When using persistent connections, jetty will close a socket connection
> if the length of the content body written does not match the
> Content-Length header set.
>
> This seems to be a bug in our software when we are using compression as
> we set the Content-Length to be the length of the uncompressed file but
> we are writing the compressed bytes over the wire.

Ah yup, that's a bug all right :) You need to either set the Content-Length
to be the length of the compressed data, or don't set the Content-Length
field at all, in which case Jetty will use chunking to output the data.

> I'd like to know why Jetty forces the connection to be closed though.
> If anyone could shed some light on the reasoning behind this, I'd be
> grateful.

The HTTP spec says that the server can close a connection to delimit
a response http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4 -
and this would seem reasonable if there's a problem with the Content-Length -
but the fundamental reason is that if you've promised to write x bytes and
then only send x-n bytes, the browser may take the next n bytes received
on that connection to complete that response. Then your message framing
will be up the spout.

cheers
Jan

> The relevant code is in org.mortbay.jetty.AbstractGenerator#complete()
>
> Sincerely,
>
> Kevin Conaway


--
Jan Bartel, Webtide LLC | [hidden email] | http://www.webtide.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email