Skip to main content

resolve_client

Function resolve_client 

Source
pub fn resolve_client(
    peer: Option<IpAddr>,
    forwarded_for: Option<&str>,
    trusted_proxies: &[String],
    proxy_depth: u32,
    fail_secure: bool,
) -> ClientResolution
Expand description

The reference client resolution an adapter runs per request.

extract_client_ip over the connecting peer, the raw X-Forwarded-For header, trusted_proxies and trusted_proxy_depth, plus the handle_passthrough rule for a request with no peer address (fail_secure rejects it unless the unix proxy token lets the chain resolve it).

ยงExample

use guard_core_engine::ip_extraction::resolve_client;

// A peer-less request under fail_secure is rejected.
assert!(resolve_client(None, None, &[], 1, true).reject);
// A trusted proxy's chain decides the client.
let resolution = resolve_client(
    Some("10.0.0.1".parse().unwrap()),
    Some("203.0.113.7"),
    &["10.0.0.0/8".to_owned()],
    1,
    true,
);
assert_eq!(resolution.ip, Some("203.0.113.7".parse().unwrap()));