Skip to content

Commit

Permalink
Fix realIP logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cl-bvl committed Nov 27, 2023
1 parent 584cb85 commit 9a4bbd4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
checker := newIPChecker(options)
return func(req *http.Request) string {
realIP := req.Header.Get(HeaderXRealIP)
remoteIP := extractIP(req)
if realIP != "" {
realIP = strings.TrimPrefix(realIP, "[")
realIP = strings.TrimSuffix(realIP, "]")
if ip := net.ParseIP(realIP); ip != nil && checker.trust(ip) {
if ip := net.ParseIP(realIP); ip != nil && checker.trust(remoteIP) {
return realIP
}
}
return extractIP(req)
return remoteIP
}
}

Expand Down

0 comments on commit 9a4bbd4

Please sign in to comment.