resolve conversation

This commit is contained in:
Notealot 2021-11-29 14:03:13 +08:00
parent 48d71d8b8d
commit 839cc536f8

10
gin.go
View File

@ -422,19 +422,22 @@ func (engine *Engine) parseTrustedProxies() error {
// isTrustedProxy will check whether the IP address is included in the trusted list according to Engine.trustedCIDRs
func (engine *Engine) isTrustedProxy(ip net.IP) bool {
if engine.trustedCIDRs != nil {
if engine.trustedCIDRs == nil {
return false
}
for _, cidr := range engine.trustedCIDRs {
if cidr.Contains(ip) {
return true
}
}
}
return false
}
// validateHeader will parse X-Forwarded-For header and return the trusted client IP address
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-- {
ipStr := strings.TrimSpace(items[i])
@ -449,7 +452,6 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
return ipStr, true
}
}
}
return "", false
}