mirror of
https://github.com/icewind1991/warp-real-ip.git
synced 2026-06-03 18:54:06 +02:00
tests
This commit is contained in:
parent
2c87a837b0
commit
58b51a72cf
4 changed files with 65 additions and 5 deletions
11
src/lib.rs
11
src/lib.rs
|
|
@ -4,10 +4,13 @@ use warp::filters::addr::remote;
|
|||
use warp::Filter;
|
||||
|
||||
/// Creates a `Filter` that provides the "real ip" of the connected client.
|
||||
pub fn real_ip<'a>(
|
||||
trusted_proxies: &'a [IpAddr],
|
||||
) -> impl Filter<Extract = (Option<IpAddr>,), Error = Infallible> + Clone + 'a {
|
||||
let forwarded_for = warp::header::<IpAddr>("X-FORWARDED-FOR")
|
||||
///
|
||||
/// 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.
|
||||
pub fn real_ip(
|
||||
trusted_proxies: Vec<IpAddr>,
|
||||
) -> impl Filter<Extract = (Option<IpAddr>,), Error = Infallible> + Clone {
|
||||
let forwarded_for = warp::header::<IpAddr>("x-forwarded-for")
|
||||
.or(warp::header("x-real-ip"))
|
||||
.unify()
|
||||
.map(Some)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue