Skip to content

Commit

Permalink
Quick Fix c.ClientIP() mistakely parsing to 127.0.0.1 for who not usi…
Browse files Browse the repository at this point in the history
…ng r.Run() to run http server (#2832)
  • Loading branch information
Bisstocuz authored and thinkerou committed Nov 24, 2021
1 parent 4ad9526 commit 7d20914
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ 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{} {
Expand Down Expand Up @@ -264,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
Original file line number Diff line number Diff line change
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 7d20914

Please sign in to comment.