mirror of https://github.com/gofiber/fiber.git
v3: router: return status 501 instead of 400 on unknown method (#2220)
* router: return status 501 instead of 400 on unknown method 501 is more applicable here. * router: ensure to always release context * ctx: fix testspull/2255/head
parent
73b43cc93e
commit
debdb8c4cd
|
@ -1402,8 +1402,8 @@ func Test_Ctx_InvalidMethod(t *testing.T) {
|
|||
|
||||
app.Handler()(fctx)
|
||||
|
||||
require.Equal(t, 400, fctx.Response.StatusCode())
|
||||
require.Equal(t, []byte("Invalid http method"), fctx.Response.Body())
|
||||
require.Equal(t, 501, fctx.Response.StatusCode())
|
||||
require.Equal(t, []byte("Not Implemented"), fctx.Response.Body())
|
||||
}
|
||||
|
||||
// go test -run Test_Ctx_MultipartForm
|
||||
|
|
|
@ -199,11 +199,11 @@ func (app *App) handler(rctx *fasthttp.RequestCtx) {
|
|||
c = app.AcquireCtx().(*DefaultCtx)
|
||||
}
|
||||
c.Reset(rctx)
|
||||
defer app.ReleaseCtx(c)
|
||||
|
||||
// handle invalid http method directly
|
||||
if methodInt(c.Method()) == -1 {
|
||||
_ = c.Status(StatusBadRequest).SendString("Invalid http method")
|
||||
app.ReleaseCtx(c)
|
||||
_ = c.SendStatus(StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -224,9 +224,6 @@ func (app *App) handler(rctx *fasthttp.RequestCtx) {
|
|||
_ = c.SendStatus(StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// Release Ctx
|
||||
app.ReleaseCtx(c)
|
||||
}
|
||||
|
||||
func (app *App) addPrefixToRoute(prefix string, route *Route) *Route {
|
||||
|
|
Loading…
Reference in New Issue