[][src]Function warp_real_ip::real_ip

pub fn real_ip(
    trusted_proxies: Vec<IpAddr>
) -> impl Filter<Extract = (Option<IpAddr>,), Error = Infallible> + Clone

Creates a Filter that provides the "real ip" of the connected client.

This uses the "x-forwarded-for" or "x-real-ip" headers set by reverse proxies. To stop clients from abusing these headers, only headers set by trusted remotes will be accepted.

Note that if multiple forwarded-for addresses are present, wich can be the case when using nested reverse proxies, all proxies in the chain have to be within the list of trusted proxies.

Example

use warp::Filter;
use warp_real_ip::real_ip;
use std::net::IpAddr;

let proxy_addr = [127, 10, 0, 1].into();
warp::any()
    .and(real_ip(vec![proxy_addr]))
    .map(|addr: Option<IpAddr>| format!("Hello {}", addr.unwrap()));