Skip to content

Commit

Permalink
HEAD requests can be made on GET routes
Browse files Browse the repository at this point in the history
  • Loading branch information
José Miguel Molina Arboledas committed Dec 12, 2013
1 parent 6f2168e commit 6e40dba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func newRoute(method string, pattern string, handlers []Handler) *route {

func (r route) Match(method string, path string) (bool, map[string]string) {
// add Any method matching support
if r.method != "*" && method != r.method {
if r.method != "*" && method != r.method && !(method == "HEAD" && r.method == "GET") {
return false, nil
}

Expand Down
9 changes: 8 additions & 1 deletion router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func Test_Routing(t *testing.T) {
t.Error(err)
}
context8 := New().createContext(recorder, req8)

req9, err := http.NewRequest("HEAD", "http://localhost:3000/foo", nil)
if err != nil {
t.Error(err)
}
context9 := New().createContext(recorder, req9)

result := ""
router.Get("/foo", func(req *http.Request) {
Expand Down Expand Up @@ -103,7 +109,8 @@ func Test_Routing(t *testing.T) {
router.Handle(recorder, req6, context6)
router.Handle(recorder, req7, context7)
router.Handle(recorder, req8, context8)
expect(t, result, "foobarbatbarfoofezpopbapwappowwappow")
router.Handle(recorder, req9, context9)
expect(t, result, "foobarbatbarfoofezpopbapwappowwappowfoo")
expect(t, recorder.Code, http.StatusNotFound)
expect(t, recorder.Body.String(), "404 page not found\n")
}
Expand Down

0 comments on commit 6e40dba

Please sign in to comment.