7

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.

Vamsi Mohan
  • 307
  • 1
  • 5
  • 13

2 Answers2

8

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.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • I wanted to understand whether response to HEAD request contains a Transfer-Encoding header set to chunked and will have not carry chunk size in hex for each chunk (without actual chunked entity) and end with a 0 followed by double CRLF. – Vamsi Mohan Jul 08 '14 at 09:45
  • HEAD response headers SHOULD be identical to a GET response. Content-Length and Transfer-Encoding MAY be omitted but it's fine if they're there. Of course there MUST NOT be a body on a HEAD response. – jamshid Nov 06 '16 at 20:14
1

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

krait
  • 785
  • 4
  • 11
  • RFC 2616 is not a W3C specification. Also it is obsoleted by RFC 7230. – Julian Reschke Jan 09 '15 at 18:30
  • Thank you for the correction. Section 4.3.2 of 7230 is a superset of the semantics in 2616 -- it elaborates that payload header fields may be omitted in a HEAD response. – krait Jan 10 '15 at 03:41