Revert "Revert "rationalize return logic in validateHeader()""

This reverts commit 84ec44d9d7aba5327a7c9b0a56484ab7377889a9.
This commit is contained in:
Notealot 2021-10-27 09:22:41 +08:00
parent 6860b6bed6
commit dd624b7cc1

7
gin.go
View File

@ -416,9 +416,7 @@ 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, ",") items := strings.Split(header, ",")
for i := len(items) - 1; i >= 0; i-- { for i := len(items) - 1; i >= 0; i-- {
ipStr := strings.TrimSpace(items[i]) ipStr := strings.TrimSpace(items[i])
@ -433,7 +431,8 @@ func (engine *Engine) validateHeader(header string) (clientIP string, valid bool
return ipStr, true return ipStr, true
} }
} }
return }
return "", false
} }
// parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs // parseTrustedProxies parse Engine.trustedProxies to Engine.trustedCIDRs