On 12 November 2014 18:13, Joakim Erdfelt <[email protected]> wrote:

> Seeing as HEAD requests, per the various RFCs, are essentially GET
> requests with complete and valid response headers, but never any content,
> having a HEAD response with Content-Length is 100% valid and appropriate.
>

Right, but it's also valid to omit the Content-Length from a HEAD response,
even if it's included in the corresponding GET.

This is particularly useful if calculating the Content-Length is expensive,
since it's often the case that you need to know the body of the response in
order to calculate its length. Omitting the Content-Length means one can
exclude that computation, and avoid all sorts of unnecessary database
lookups.

My particular use case is that I maintain a Clojure wrapper around Jetty,
and the wrapper doesn't necessarily have all the data it needs to calculate
the content length in the case of a HEAD request. This should be fine, as
the Content-Length header can be omitted, but I have yet to work out a way
of convincing Jetty to do that.

I've tried not setting the content length, setting it to null, and setting
it to -1, but this just results in a header value of "0". My investigations
into the source code of Jetty make me suspect that the Content-Length
header might be hard-coded into the response renderer, but I really hope
that's not the case. It seems like there should be a way of doing it, since
it's a pretty simple operation.

- James
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to