HTTP HEAD and GET different result

2019-06-25 11:05发布

问题:

Should the HEAD and GET methods return the same status code? More specifically, we have run into the situation where a client website is returning a 200 when we do a HEAD, but returns a 303 when we do a GET. It has to do with redirecting to a language specific page based on location, but shouldn't the HEAD then also ask you to redirect?

回答1:

but shouldn't the HEAD then also ask you to redirect?

The key is the word SHOULD. From the HTTP method specification, RFC2616:

9.4 HEAD

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.

The word SHOULD is further definied in RFC2119:

SHOULD This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

So, the case you described is legit, but not recommended. You may want to ask the site maintainer for the reasoning of this path.