Re: P1: Content-Length SHOULD be sent

On Mon, Nov 26, 2012 at 11:21 PM, Mark Nottingham <mnot@mnot.net> wrote:
> Currently, p1 says:
>
>> When a message is allowed to contain a message body, does not have a Transfer-Encoding header field, and has a payload body length that is known to the sender before the message header section has been sent, the sender should send a Content-Length header field to indicate the length of the payload body as a decimal number of octets.
>
> This unqualified SHOULD leads people to convoluted readings of the spec where Content-Length is required to be sent on a GET request:
>   https://github.com/kennethreitz/requests/issues/223#issuecomment-10745532
>
> Proposal:
>
>> When a message is allowed to contain a body, does not have a Transfer-Encoding header field, and has a payload body length that is known to the sender before the message header section has been sent, the sender should send a Content-Length header field to indicate the length of the payload body as a decimal number of octets, unless the message is a request and the payload length is zero (in which case the Content-Length header MAY be sent).

Isn't there a semantic difference between a request without a payload
and a request with an empty payload?

If a POST request payload is empty (which is perfectly valid, e.g. an
HTML form post without parameters), and it doesn't include
"Content-Length:0", it may break server implementations, because the
server checks whether a request has an "entity" based on
Content-Length/Transfer-Encoding, regardless of request method. If
Content-Length:0 is missing, the server will think that this is a POST
request without "entity", which it is probably unprepared for.

Zhong Yu

>
>
> --
> Mark Nottingham   http://www.mnot.net/
>
>
>
>

Received on Tuesday, 27 November 2012 15:03:57 UTC