Added convenient shortcut for OPTIONS
diff --git a/router.go b/router.go index 8fa9520..5172c89 100644 --- a/router.go +++ b/router.go
@@ -178,6 +178,11 @@ r.Handle("HEAD", path, handle) } +// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle) +func (r *Router) OPTIONS(path string, handle Handle) { + r.Handle("OPTIONS", 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 75d2dfc..835caf0 100644 --- a/router_test.go +++ b/router_test.go
@@ -76,7 +76,7 @@ } func TestRouterAPI(t *testing.T) { - var get, head, post, put, patch, delete, handler, handlerFunc bool + var get, head, options, post, put, patch, delete, handler, handlerFunc bool httpHandler := handlerStruct{&handler} @@ -87,6 +87,9 @@ router.HEAD("/GET", func(w http.ResponseWriter, r *http.Request, _ Params) { head = true }) + router.OPTIONS("/GET", func(w http.ResponseWriter, r *http.Request, _ Params) { + options = true + }) router.POST("/POST", func(w http.ResponseWriter, r *http.Request, _ Params) { post = true }) @@ -118,6 +121,12 @@ t.Error("routing HEAD failed") } + r, _ = http.NewRequest("OPTIONS", "/GET", nil) + router.ServeHTTP(w, r) + if !head { + t.Error("routing OPTIONS failed") + } + r, _ = http.NewRequest("POST", "/POST", nil) router.ServeHTTP(w, r) if !post {