Hi. I was wondering what was behind the design decision for django.views.generic.base.View.dispatch:
By default, a HEAD request will be delegated to get(). If you need to handle HEAD requests in a different way than GET, you can override the head() method. See Supporting other HTTP methods for an example.
I knew about this for a long time but i guess i never really realized the performance penalty for this as many monitoring services (correctly) use HEAD to “be polite” when checking an application is up and basically dont care about the body as per the RFC they can’t even get it:
The HTTP
HEADmethod requests the headers that would be returned if theHEADrequest’s URL was instead requested with the HTTPGETmethod.
Warning: A response to a
HEADmethod should not have a body. If it has one anyway, that body must be ignored: any representation headers that might describe the erroneous body are instead assumed to describe the response which a similarGETrequest would have received.
Having nginx in front of django+uwsgi looks like this:
nginx:
aa.bb.cc.dd - - [13/Jul/2023:12:07:10 +0000] "HEAD / HTTP/1.1" 200 0 "https://example.com" "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)" 0.131 TLSv1.2
django:
2023-07-13 12:07:10 aa.bb.cc.dd "HEAD / HTTP/1.1" 200 164833 "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)" 0.131188