From 27fabb143c41397d030dcd01b3ba2560e9d7f4bf Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Fri, 20 Aug 2021 01:37:51 +0800 Subject: [PATCH 1/5] Quick Fix #2814 --- gin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gin.go b/gin.go index 6ab2be66d0..ff15a499ec 100644 --- a/gin.go +++ b/gin.go @@ -188,6 +188,7 @@ func New() *Engine { engine.pool.New = func() interface{} { return engine.allocateContext() } + engine.trustedCIDRs, _ = engine.prepareTrustedCIDRs() return engine } From c2e6c7ed9d31f000b2b8b913ab36025b99b4f5a1 Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Mon, 13 Sep 2021 01:48:57 +0800 Subject: [PATCH 2/5] Resolve review --- gin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gin.go b/gin.go index ff15a499ec..320cb37498 100644 --- a/gin.go +++ b/gin.go @@ -188,7 +188,7 @@ func New() *Engine { engine.pool.New = func() interface{} { return engine.allocateContext() } - engine.trustedCIDRs, _ = engine.prepareTrustedCIDRs() + _ = engine.parseTrustedProxies() return engine } From c7e3b728fb490b8a0d836396298a457b625c13f2 Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Wed, 22 Sep 2021 16:23:32 +0800 Subject: [PATCH 3/5] initialize trustedCIDRs directly directly initialization --- gin.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gin.go b/gin.go index 320cb37498..5584bf0c99 100644 --- a/gin.go +++ b/gin.go @@ -183,12 +183,16 @@ func New() *Engine { trees: make(methodTrees, 0, 9), delims: render.Delims{Left: "{{", Right: "}}"}, secureJSONPrefix: "while(1);", + trustedCIDRs: []*net.IPNet{{IP: net.IP{0x0, 0x0, 0x0, 0x0}, Mask: net.IPMask{0x0, 0x0, 0x0, 0x0}}}, } engine.RouterGroup.engine = engine engine.pool.New = func() interface{} { return engine.allocateContext() } +<<<<<<< Updated upstream _ = engine.parseTrustedProxies() +======= +>>>>>>> Stashed changes return engine } From 25af02a308dd977dd7305f0c6fe1bcd0242d7d40 Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Wed, 22 Sep 2021 16:43:38 +0800 Subject: [PATCH 4/5] initialize trustedCIDRs directly directly initialization --- gin.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gin.go b/gin.go index 5584bf0c99..d0b02a5896 100644 --- a/gin.go +++ b/gin.go @@ -189,10 +189,6 @@ func New() *Engine { engine.pool.New = func() interface{} { return engine.allocateContext() } -<<<<<<< Updated upstream - _ = engine.parseTrustedProxies() -======= ->>>>>>> Stashed changes return engine } From 265d06aaa076cb06a3f4e5b6bebe3238875b754c Mon Sep 17 00:00:00 2001 From: Notealot <714804968@qq.com> Date: Wed, 29 Sep 2021 16:19:05 +0800 Subject: [PATCH 5/5] Fixed #2871 #2872 --- gin.go | 3 +-- middleware_test.go | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gin.go b/gin.go index 9b33f024b1..02a1062c31 100644 --- a/gin.go +++ b/gin.go @@ -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() } diff --git a/middleware_test.go b/middleware_test.go index fca1c530b3..4b4afd4af0 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -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", "/")