Ensure an empty body in response to a HEAD request

Addresses #35
This commit is contained in:
Marius 2015-12-02 18:59:22 +01:00
parent 88aed988f9
commit dd6ce92651
2 changed files with 7 additions and 2 deletions

View File

@ -457,6 +457,8 @@ func (handler *Handler) sendError(w http.ResponseWriter, r *http.Request, err er
}
reason := err.Error() + "\n"
// Avoid sending a response to a HEAD request. They expect an empty body.
if r.Method == "HEAD" {
reason = ""
}

View File

@ -53,7 +53,7 @@ func TestHead(t *testing.T) {
t.Errorf("Expected valid metadata (got '%s')", v)
}
(&httpTest{
res = (&httpTest{
Name: "Non-existing file",
Method: "HEAD",
URL: "no",
@ -64,6 +64,9 @@ func TestHead(t *testing.T) {
ResHeader: map[string]string{
"Content-Length": "0",
},
ResBody: "",
}).Run(handler, t)
if string(res.Body.Bytes()) != "" {
t.Errorf("Expected empty body for failed HEAD request")
}
}