Merge branch 'master' of https://github.com/dahankzter/httprouter into dahankzter-master
Conflicts:
router_test.go
diff --git a/router.go b/router.go
index 3f3d163..a6be43c 100644
--- a/router.go
+++ b/router.go
@@ -159,6 +159,11 @@
r.Handle("GET", path, handle)
}
+// HEAD is a shortcut for router.Handle("HEAD", path, handle)
+func (r *Router) HEAD(path string, handle Handle) {
+ r.Handle("HEAD", path, handle)
+}
+
// POST is a shortcut for router.Handle("POST", path, handle)
func (r *Router) POST(path string, handle Handle) {
r.Handle("POST", path, handle)
diff --git a/router_test.go b/router_test.go
index ca59066..08dab29 100644
--- a/router_test.go
+++ b/router_test.go
@@ -76,7 +76,7 @@
}
func TestRouterAPI(t *testing.T) {
- var get, post, put, patch, delete, handler, handlerFunc bool
+ var get, head, post, put, patch, delete, handler, handlerFunc bool
httpHandler := handlerStruct{&handler}
@@ -84,6 +84,9 @@
router.GET("/GET", func(w http.ResponseWriter, r *http.Request, _ Params) {
get = true
})
+ router.HEAD("/GET", func(w http.ResponseWriter, r *http.Request, _ Params) {
+ head = true
+ })
router.POST("/POST", func(w http.ResponseWriter, r *http.Request, _ Params) {
post = true
})
@@ -109,6 +112,12 @@
t.Error("routing GET failed")
}
+ r, _ = http.NewRequest("HEAD", "/GET", nil)
+ router.ServeHTTP(w, r)
+ if !head {
+ t.Error("routing HEAD failed")
+ }
+
r, _ = http.NewRequest("POST", "/POST", nil)
router.ServeHTTP(w, r)
if !post {