What response header should HTTP HEAD method get for a dynamically generated file?

怎甘沉沦 提交于 2020-01-03 06:04:28

问题


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.

And also:

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.

So if the requested resource is dynamically generated, for the HEAD request, will the resource ALSO be generated? Should there a Content-Length header or Transfer-Encoding: chunked header?

(I feel this is about how to implement the HTTP protocol.)

ADD 1

I don't see the spec mandates whether to send Content-Length header or how to send it for a dynamically generated resource. Such dynamic resource will be sent with chunked transfer encoding and there'll be no Content-Length header if accessed with a GET method. So, if HEAD response should mimic GET response, the Contnet-Length should not be sent either.


回答1:


a) That's not the HTTP spec. It is the W3C copy of the now obsolete RFC 2616, dated 1999.

b) For the current spec, see https://greenbytes.de/tech/webdav/rfc7231.html#HEAD

To answer your question: if you don't know the payload size without actually generating it, not sending Content-Length in the HEAD response is ok.



来源:https://stackoverflow.com/questions/38008095/what-response-header-should-http-head-method-get-for-a-dynamically-generated-fil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!