Skip to main content

client_ip

Function client_ip 

Source
pub fn client_ip(
    headers: &HeaderMap,
    trusted: &[String],
    peer: Option<IpAddr>,
) -> Option<IpAddr>
Expand description

The client IP for one request, in trust order:

  1. the first trusted_proxy_headers header present with a value whose first comma-separated entry parses as an IP address;
  2. else the TCP peer address the server observed.

None only when both are unavailable (no trusted header matched and the middleware ran without connection info, e.g. a test’s oneshot).

This function decides; the server middleware enforces. It resolves the address here, strips every forwarding header, and writes the result into CLIENT_IP_HEADER — so by the time a module calls cratefield_core::client_ip(headers), the only forwarding header left carries exactly this runtime’s verdict.