diff --git a/router_test.go b/router_test.go index d1e2d463..66994f40 100644 --- a/router_test.go +++ b/router_test.go @@ -199,6 +199,24 @@ func registerDummyRoutes(app *App) { } } +// go test -v -run=^$ -bench=Benchmark_App_Benchmark_App_MethodNotAllowed -benchmem -count=4 +func Benchmark_App_MethodNotAllowed(b *testing.B) { + app := New() + app.Get("/this/is/a/dummy/route/oke", func(c *Ctx) { + c.Send("Hello World!") + }) + c := &fasthttp.RequestCtx{} + + c.Request.Header.SetMethod("DELETE") + c.URI().SetPath("/this/is/a/dummy/route/oke") + + for n := 0; n < b.N; n++ { + app.handler(c) + } + utils.AssertEqual(b, 405, c.Response.StatusCode()) + utils.AssertEqual(b, "GET, HEAD", string(c.Response.Header.Peek("Allow"))) +} + // go test -v ./... -run=^$ -bench=Benchmark_Router_NotFound -benchmem -count=4 func Benchmark_Router_NotFound(b *testing.B) { app := New() diff --git a/utils.go b/utils.go index 920e554a..695b0899 100644 --- a/utils.go +++ b/utils.go @@ -211,7 +211,7 @@ var methodINT = map[string]int{ MethodPatch: 8, } -// HTTP methods and their unique INTs +// HTTP methods slice var intMethod = []string{ MethodGet, MethodHead,