feat(botfilter): add util.go
This commit is contained in:
1 parent
e106a1086c
commit
fcfe9ee976
1 file changed
+11
@@ -15,3 +15,14 @@ func clientIP(r *http.Request, cfg *compiledConfig) netip.Addr {
|
||||
return remote
|
||||
}
|
||||
|
||||
// A trusted reverse proxy must overwrite (not append to an untrusted
|
||||
// client-provided value) this header. The left-most valid value is the
|
||||
// original client in the conventional X-Forwarded-For representation.
|
||||
for _, value := range strings.Split(r.Header.Get(cfg.clientIPHeader), ",") {
|
||||
if addr, err := netip.ParseAddr(strings.TrimSpace(value)); err == nil {
|
||||
return addr.Unmap()
|
||||
}
|
||||
}
|
||||
return remote
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user