Skip to content

Commit

Permalink
clarify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Jan 20, 2022
1 parent 4118840 commit 81a7d31
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions realip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ func GetIPAddress(r *http.Request) (string, error) {
// that will be the address right before our proxy.
for i := len(addresses) - 1; i >= 0; i-- {
ip := strings.TrimSpace(addresses[i])
// header can contain spaces too, strip those out.
realIP := net.ParseIP(ip)
if !realIP.IsGlobalUnicast() || isPrivateSubnet(realIP) {
// bad address, go to next
continue
}
return ip, nil
}
}

// X-Forwarded-For set but failed on previous checks
// X-Forwarded-For header set but parsing failed above
if r.Header.Get("X-Forwarded-For") != "" {
return "", fmt.Errorf("no valid ip found")
}
Expand Down

0 comments on commit 81a7d31

Please sign in to comment.