Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content-Length header with HEAD requests?

The http spec says about the HEAD request:

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.

Should the response to a HEAD request contain a Content-Length header? Should it be the value which would be returned on a GET request, even if there is no response body? Or should the Content-Length be 0?

like image 575
deamon Avatar asked Oct 04 '10 11:10

deamon


People also ask

How do you add Content Length in request header?

To manually pass the Content-Length header, you need to add the Content-Length: [length] and Content-Type: [mime type] headers to your request, which describe the size and type of data in the body of the POST request.

What is Content Length in request header?

The Content-Length header indicates the size of the message body, in bytes, sent to the recipient.

Is Content Length header required request?

The Content-Length header is mandatory for messages with entity bodies, unless the message is transported using chunked encoding. Content-Length is needed to detect premature message truncation when servers crash and to properly segment messages that share a persistent connection.

What should be the Content Length?

The content-length is the size of the compressed message body, in "octets" (i.e. in units of 8 bits, which happen to be "bytes" for all modern computers). The size of the actual message body can be something else, perhaps 150280 bytes.


1 Answers

To me it looks like the HTTP 1.1 RFC is pretty specific:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

like image 95
nietaki Avatar answered Oct 17 '22 09:10

nietaki