Skip to content

Commit 7d20914

Browse files
Bisstocuzthinkerou
authored andcommitted
Quick Fix c.ClientIP() mistakely parsing to 127.0.0.1 for who not using r.Run() to run http server (#2832)
1 parent 4ad9526 commit 7d20914

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

gin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func New() *Engine {
183183
trees: make(methodTrees, 0, 9),
184184
delims: render.Delims{Left: "{{", Right: "}}"},
185185
secureJSONPrefix: "while(1);",
186+
trustedCIDRs: []*net.IPNet{{IP: net.IP{0x0, 0x0, 0x0, 0x0}, Mask: net.IPMask{0x0, 0x0, 0x0, 0x0}}},
186187
}
187188
engine.RouterGroup.engine = engine
188189
engine.pool.New = func() interface{} {
@@ -264,9 +265,8 @@ func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
264265
engine.rebuild404Handlers()
265266
}
266267

267-
// NoMethod sets the handlers called when NoMethod.
268+
// NoMethod sets the handlers called when Engine.HandleMethodNotAllowed = true.
268269
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
269-
engine.HandleMethodNotAllowed = true
270270
engine.noMethod = handlers
271271
engine.rebuild405Handlers()
272272
}

middleware_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ func TestMiddlewareNoMethodEnabled(t *testing.T) {
118118
func TestMiddlewareNoMethodDisabled(t *testing.T) {
119119
signature := ""
120120
router := New()
121+
122+
// NoMethod disabled
121123
router.HandleMethodNotAllowed = false
124+
122125
router.Use(func(c *Context) {
123126
signature += "A"
124127
c.Next()
@@ -144,6 +147,7 @@ func TestMiddlewareNoMethodDisabled(t *testing.T) {
144147
router.POST("/", func(c *Context) {
145148
signature += " XX "
146149
})
150+
147151
// RUN
148152
w := performRequest(router, "GET", "/")
149153

0 commit comments

Comments
 (0)