Documentation
¶
Index ¶
- Constants
- func ParsePrefixes(cidrs []string) ([]netip.Prefix, error)
- func RealIP(r *http.Request, trustedProxies []netip.Prefix) string
- func RemoteAddrIP(remoteAddr string) (addr netip.Addr, fallback string, ok bool)
- func Scheme(r *http.Request, trustedProxies []netip.Prefix) string
- func Trusted(prefixes []netip.Prefix, addr netip.Addr) bool
Constants ¶
const MaxForwardedForHops = 32
MaxForwardedForHops limits the amount of X-Forwarded-For entries inspected per request. The trusted chain is walked from the right, closest to the app.
Variables ¶
This section is empty.
Functions ¶
func ParsePrefixes ¶
ParsePrefixes parses trusted proxy CIDR strings once at application startup.
func RealIP ¶
RealIP reports the original client IP when the immediate peer is trusted. The RFC 7239 Forwarded header (for= parameters) takes precedence over the legacy X-Forwarded-For and X-Real-IP headers; all chain sources are walked with the same right-to-left trusted-hop semantics.
func RemoteAddrIP ¶
RemoteAddrIP parses an http.Request RemoteAddr and returns an IP-only string for valid addresses. If RemoteAddr is unparseable, fallback is the trimmed RemoteAddr value and ok is false.
Types ¶
This section is empty.