This commit is contained in:
Notealot 2021-09-29 16:19:05 +08:00
parent 7f40bb7947
commit 265d06aaa0
2 changed files with 5 additions and 2 deletions

3
gin.go
View File

@ -265,9 +265,8 @@ func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
engine.rebuild404Handlers()
}
// NoMethod sets the handlers called when NoMethod.
// NoMethod sets the handlers called when Engine.HandleMethodNotAllowed = true.
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
engine.HandleMethodNotAllowed = true
engine.noMethod = handlers
engine.rebuild405Handlers()
}

View File

@ -118,7 +118,10 @@ func TestMiddlewareNoMethodEnabled(t *testing.T) {
func TestMiddlewareNoMethodDisabled(t *testing.T) {
signature := ""
router := New()
// NoMethod disabled
router.HandleMethodNotAllowed = false
router.Use(func(c *Context) {
signature += "A"
c.Next()
@ -144,6 +147,7 @@ func TestMiddlewareNoMethodDisabled(t *testing.T) {
router.POST("/", func(c *Context) {
signature += " XX "
})
// RUN
w := performRequest(router, "GET", "/")