pub fn client_ip(
headers: &HeaderMap,
trusted: &[String],
peer: Option<IpAddr>,
) -> Option<IpAddr>Expand description
The client IP for one request, in trust order:
- the first
trusted_proxy_headersheader present with a value whose first comma-separated entry parses as an IP address; - 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.