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 (gin-gonic#2832)

(cherry picked from commit 6d75aba)
  • Loading branch information
Bisstocuz committed Nov 22, 2021
1 parent 5bd2f6e commit b989a6e
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 @@ -168,6 +168,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 @@ -249,9 +250,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 b989a6e

Please sign in to comment.