mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
Revert "rationalize return logic in validateHeader()"
This reverts commit 513b59fa8875d77c86f122af4bb0cc547eb98c8f.
This commit is contained in:
parent
513b59fa88
commit
84ec44d9d7
29
gin.go
29
gin.go
@ -416,23 +416,24 @@ func (engine *Engine) isTrustedProxy(ip net.IP) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) validateHeader(header string) (clientIP string, valid bool) {
|
func (engine *Engine) validateHeader(header string) (clientIP string, valid bool) {
|
||||||
if header != "" {
|
if header == "" {
|
||||||
items := strings.Split(header, ",")
|
return "", false
|
||||||
for i := len(items) - 1; i >= 0; i-- {
|
}
|
||||||
ipStr := strings.TrimSpace(items[i])
|
items := strings.Split(header, ",")
|
||||||
ip := net.ParseIP(ipStr)
|
for i := len(items) - 1; i >= 0; i-- {
|
||||||
if ip == nil {
|
ipStr := strings.TrimSpace(items[i])
|
||||||
return "", false
|
ip := net.ParseIP(ipStr)
|
||||||
}
|
if ip == nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
// X-Forwarded-For is appended by proxy
|
// X-Forwarded-For is appended by proxy
|
||||||
// Check IPs in reverse order and stop when find untrusted proxy
|
// Check IPs in reverse order and stop when find untrusted proxy
|
||||||
if (i == 0) || (!engine.isTrustedProxy(ip)) {
|
if (i == 0) || (!engine.isTrustedProxy(ip)) {
|
||||||
return ipStr, true
|
return ipStr, true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs
|
// parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user