mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 05:42:09 +08:00
Revert "Revert "rationalize return logic in validateHeader()""
This reverts commit 84ec44d9d7aba5327a7c9b0a56484ab7377889a9.
This commit is contained in:
parent
6860b6bed6
commit
dd624b7cc1
29
gin.go
29
gin.go
@ -416,24 +416,23 @@ 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 != "" {
|
||||||
return "", false
|
items := strings.Split(header, ",")
|
||||||
}
|
for i := len(items) - 1; i >= 0; i-- {
|
||||||
items := strings.Split(header, ",")
|
ipStr := strings.TrimSpace(items[i])
|
||||||
for i := len(items) - 1; i >= 0; i-- {
|
ip := net.ParseIP(ipStr)
|
||||||
ipStr := strings.TrimSpace(items[i])
|
if ip == nil {
|
||||||
ip := net.ParseIP(ipStr)
|
return "", false
|
||||||
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
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs
|
// parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user