Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I be responding to HTTP HEAD requests on my website

My google app engine website is getting errors on the main url for HEAD requests because I am not accepting them. According to this, the HEAD request is for "testing hypertext links for validity, accessibility, and recent modification"

What should be my "normal" response to HEAD requests be?

I started accepting HEAD requests, to stop the errors from showing in my logs, but only on the main url.

Can someone point me in the right direction?

like image 414
bentford Avatar asked Oct 01 '09 02:10

bentford


People also ask

When should you use the HTTP HEAD method?

The HEAD method is used to ask only for information about a document, not for the document itself. HEAD is much faster than GET, as a much smaller amount of data is transferred. It's often used by clients who use caching, to see if the document has changed since it was last accessed.

What are head requests used for?

What is the HTTP HEAD request method used for? The HTTP HEAD request is used to check the availability, size, and last modification date of a resource without downloading it (as indicated by the Content-Length and Last-Modified headers).

Are head requests faster than get?

It is indeed plausible that a HEAD request would complete faster than GET, since it involves less data transfer. However, on a fast or high latency connection this almost always won't matter.

Which method is responsible for performing HTTP HEAD operation?

The HTTP HEAD method is almost identical to the GET method, but the only difference is that it will not return any response body. For example, if GET/users return a record of users, then HEAD/users make the same request, but it will not return any of the users' records.


1 Answers

Implement you head method(s) just like the get one(s), just skipping the writing of the body. You should do that for every URL that can be linked to, exactly because a well-behaved checker that's validating the links should use HEAD when it doesn't need the body.

Simplest is often to factor out the get functionality to a separate auxiliary method _foo that takes a boolean needbody argument -- get calls self._foo(True), head calls self._foo(False). _foo, if it sees its needbody argument is false, can bail out as soon as it has generated all headers (and must make sure it doesn't generate a body).

like image 171
Alex Martelli Avatar answered Sep 18 '22 12:09

Alex Martelli