Skip to main content

real_ip_from_forwarded_for

Function real_ip_from_forwarded_for 

Source
pub fn real_ip_from_forwarded_for(
    x_forwarded_for: Option<&str>,
    peer: IpAddr,
    trusted: &[IpNet],
) -> IpAddr
Expand description

Returns the first client IP from X-Forwarded-For only when peer is trusted.

The leftmost value is used because application reverse proxies append their own address to the right. If the peer is not trusted, the header is ignored. Malformed or empty header values fall back to the direct peer address.