简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM