D2 & Web-Framework

Adam Ruppe destructionator at gmail.com
Fri Jul 15 14:34:21 PDT 2011


Nick Sabalausky wrote:
> But, HEAD is technically required (though I have no idea what the
> real-world use-cases are), so I'm not quite sure what to do.

Actually, I'd be surprised if your web server didn't handle it...
it can just send a GET to your app then simply discard the response
body.

As for use, I think it's actually a carryover from http 1.0, rendered
almost useless in http 1.1 thanks to it's conditional get. I believe
they weren't in 1.0, so if you wanted to check for a new version of
a page, instead of saying "get if modified since", you'd do a HEAD
and check the last modified header yourself, then issuing a separate
GET if it's old enough.

Obviously, a conditional get is a much better way to do it.


The only two things I find HEAD useful for myself are:

a) testing. It's nice to be able to manually do a request and not be
spammed by a million lines of body when I just want to see headers.

b) making sure a file is a reasonable size before downloading. Since
content-length is one of the headers in this, you can check the size
and present it to the user to cancel if it's unreasonable.

I don't think there's another way to do (b) in the 1.1 version. It's
definitely how I'd do it.


More information about the Digitalmars-d mailing list