From c89bfb36348518f64d3cb791e222af3984f1ca4b Mon Sep 17 00:00:00 2001 From: kiyon Date: Fri, 17 Jul 2020 09:34:27 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=94=20fix=20ctx=20matched=20bug,=20it?= =?UTF-8?q?=20should=20be=20reset=20to=20false=20when=20acquired?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_test.go | 7 ++++++- ctx.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app_test.go b/app_test.go index c59d1fef87..ed213b080e 100644 --- a/app_test.go +++ b/app_test.go @@ -40,7 +40,12 @@ func Test_App_MethodNotAllowed(t *testing.T) { app.Options("/", func(c *Ctx) {}) - resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) + resp, err := app.Test(httptest.NewRequest("POST", "/", nil)) + utils.AssertEqual(t, nil, err) + utils.AssertEqual(t, 200, resp.StatusCode) + utils.AssertEqual(t, "", resp.Header.Get(HeaderAllow)) + + resp, err = app.Test(httptest.NewRequest("GET", "/", nil)) utils.AssertEqual(t, nil, err) utils.AssertEqual(t, 405, resp.StatusCode) utils.AssertEqual(t, "POST, OPTIONS", resp.Header.Get(HeaderAllow)) diff --git a/ctx.go b/ctx.go index 5ab4c684fd..9077825e2d 100644 --- a/ctx.go +++ b/ctx.go @@ -87,6 +87,8 @@ func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) *Ctx { // Reset route and handler index ctx.indexRoute = -1 ctx.indexHandler = 0 + // Reset matched flag + ctx.matched = false // Set paths ctx.path = getString(fctx.URI().PathOriginal()) ctx.pathOriginal = ctx.path