1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 09:43:40 +00:00

🔔 fix ctx matched bug, it should be reset to false when acquired

This commit is contained in:
kiyon 2020-07-17 09:34:27 +08:00 committed by ReneWerner87
parent 2e1dde0c1d
commit 95362e51b6
2 changed files with 8 additions and 1 deletions

View File

@ -40,7 +40,12 @@ func Test_App_MethodNotAllowed(t *testing.T) {
app.Options("/", func(c *Ctx) {}) 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, nil, err)
utils.AssertEqual(t, 405, resp.StatusCode) utils.AssertEqual(t, 405, resp.StatusCode)
utils.AssertEqual(t, "POST, OPTIONS", resp.Header.Get(HeaderAllow)) utils.AssertEqual(t, "POST, OPTIONS", resp.Header.Get(HeaderAllow))

2
ctx.go
View File

@ -87,6 +87,8 @@ func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) *Ctx {
// Reset route and handler index // Reset route and handler index
ctx.indexRoute = -1 ctx.indexRoute = -1
ctx.indexHandler = 0 ctx.indexHandler = 0
// Reset matched flag
ctx.matched = false
// Set paths // Set paths
ctx.path = getString(fctx.URI().PathOriginal()) ctx.path = getString(fctx.URI().PathOriginal())
ctx.pathOriginal = ctx.path ctx.pathOriginal = ctx.path