MatchMethodThe method routing functions use a class (MatchMethod method) instead of the concrete type Method.
This allows us to easily match on more than one method by either providing a list of acceptable matches, or by providing a function which returns a boolean value. We can use this feature to support the HEAD method. When the client does a HEAD request, the server is supposed to return the same headers it would for a GET request, but with an empty response body. Happstack includes special support for handling this automatically in most cases.
[Source code for the app is here.]
We can now use curl to do a normal GET request, or we can
use the -I flag which does a HEAD request:
$ curl http://localhost:8000/ Hello, World $ curl -I http://localhost:8000/ HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 13 Content-Type: text/plain; charset=UTF-8 Date: Tue, 15 Jun 2010 19:56:07 GMT Server: Happstack/0.5.0
Happstack automatically notices that it is a HEAD request, and does not send the body.