Allow HEAD for all GET resources.

This commit is contained in:
Jacob Hoffman-Andrews 2015-09-27 12:36:18 -07:00
parent 7a10b3c546
commit ecd08c0798
2 changed files with 6 additions and 4 deletions

View File

@ -154,8 +154,9 @@ func (mrw BodylessResponseWriter) Write(buf []byte) (int, error) {
// * Respond http.StatusMethodNotAllowed for HTTP methods other than
// those listed.
//
// * Never send a body in response to a HEAD request. (Anything
// written by the handler will be discarded if the method is HEAD.)
// * Never send a body in response to a HEAD request. Anything
// written by the handler will be discarded if the method is HEAD. Also, all
// handlers that accept GET automatically accept HEAD.
func (wfe *WebFrontEndImpl) HandleFunc(mux *http.ServeMux, pattern string, h func(http.ResponseWriter, *http.Request), methods ...string) {
methodsOK := make(map[string]bool)
for _, m := range methods {
@ -176,6 +177,8 @@ func (wfe *WebFrontEndImpl) HandleFunc(mux *http.ServeMux, pattern string, h fun
// should still comply with HTTP spec by not
// sending a body.
response = BodylessResponseWriter{response}
h(response, request)
return
case "OPTIONS":
// TODO, #469
}

View File

@ -308,9 +308,8 @@ func TestHandleFunc(t *testing.T) {
// Disallowed method special case: response to HEAD has got no body
runWrappedHandler(&http.Request{Method: "HEAD"}, "GET", "POST")
test.AssertEquals(t, stubCalled, false)
test.AssertEquals(t, stubCalled, true)
test.AssertEquals(t, rw.Body.String(), "")
test.AssertEquals(t, sortHeader(rw.Header().Get("Allow")), "GET, POST")
}
func TestStandardHeaders(t *testing.T) {