pub fn extract_client_ip(
headers: &HeaderMap,
trusted_proxies: &[IpNet],
connect_ip: Option<IpAddr>,
) -> IpAddrExpand description
Resolve the real client IP from headers and connection info.
Resolution order:
- If
trusted_proxiesis non-empty,connect_ipisSome, andconnect_ipis NOT contained in any trusted range → returnconnect_ip(the peer connected directly, so proxy headers must be ignored to avoid spoofing). X-Forwarded-For→ leftmost entry that parses as anIpAddr.X-Real-IP→ value parsed as anIpAddr.connect_ipif provided.127.0.0.1as final fallback.
This is the low-level primitive used by ClientIpLayer;
prefer the layer in HTTP handlers and call this directly only when you
already have a HeaderMap without a Tower stack.