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 20, 2021
1 parent 92eeaa4 commit 3783ce0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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,7 +250,7 @@ func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
engine.rebuild404Handlers()
}

// NoMethod sets the handlers called when... TODO.
// NoMethod sets the handlers called when Engine.HandleMethodNotAllowed = true.
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
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 3783ce0

Please sign in to comment.