Skip to content

Commit

Permalink
Fixed #2871 #2872
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisstocuz committed Sep 29, 2021
1 parent 7f40bb7 commit 265d06a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions gin.go
Expand Up @@ -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()
}
Expand Down
4 changes: 4 additions & 0 deletions middleware_test.go
Expand Up @@ -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()
Expand All @@ -144,6 +147,7 @@ func TestMiddlewareNoMethodDisabled(t *testing.T) {
router.POST("/", func(c *Context) {
signature += " XX "
})

// RUN
w := performRequest(router, "GET", "/")

Expand Down

0 comments on commit 265d06a

Please sign in to comment.