views:

62

answers:

1

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?

+2  A: 

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).

Alex Martelli
Another option, in webapp, is to define a base class that implements head by calling self.get then erasing the body. This is inefficient, of course, but lets you override it more efficiently on a case-by-case basis.
Nick Johnson