Added convenient shortcut for HEAD
diff --git a/router.go b/router.go
index 5c0a99b..1c31bdb 100644
--- a/router.go
+++ b/router.go
@@ -134,6 +134,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 0298a5e..bb8aa02 100644
--- a/router_test.go
+++ b/router_test.go
@@ -52,12 +52,15 @@
}
func TestRouterAPI(t *testing.T) {
- var get, post, put, patch, delete, handlerFunc bool
+ var get, head, post, put, patch, delete, handlerFunc bool
router := New()
router.GET("/GET", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
get = true
})
+ router.HEAD("/GET", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
+ head = true
+ })
router.POST("/POST", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
post = true
})
@@ -82,6 +85,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 {