Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should HTTP Server respond to HEAD request for chunked encoding

I have a question on how does a HTTP Server response look like when a HEAD is sent to a resource and server decided to perform chunked encoding?

If a Server always wishes to perform chunked encoding for a GET on a specific resource, as it does not know the exact content-length while generating response, how should server behave when a HEAD is sent on the same resource.

like image 981
Vamsi Mohan Avatar asked Jul 08 '14 07:07

Vamsi Mohan


2 Answers

The Transfer-Encoding header field is an aspect of the payload. For HEAD responses, you don't have a payload, thus no Transfer-Encoding header field; even if it would be used upon GET.

like image 190
Julian Reschke Avatar answered Nov 03 '22 01:11

Julian Reschke


According to the W3C's specification:

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.

This means that if a response to a GET request contains Transfer-Encoding: chunked then the response to a corresponding HEAD request should contain that header too.

You can verify this in the wild:

curl -I http://www.google.com/ # -I sends HEAD request

HTTP/1.1 200 OK Date: Fri, 09 Jan 2015 17:56:05 GMT Expires: -1 Cache-Control: private, max-age=0 Content-Type: text/html; charset=ISO-8859-1 Server: gws X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN Alternate-Protocol: 80:quic,p=0.02 Transfer-Encoding: chunked

like image 44
krait Avatar answered Nov 03 '22 01:11

krait