mirror of
https://github.com/icewind1991/warp-real-ip.git
synced 2026-06-03 10:44:07 +02:00
readme
This commit is contained in:
parent
96d3dc45cf
commit
14b44fb00c
2 changed files with 32 additions and 0 deletions
19
README.md
Normal file
19
README.md
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# wrap-real-ip
|
||||||
|
|
||||||
|
Warp filter to get the "real ip" of the remote 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.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```rust
|
||||||
|
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()));
|
||||||
|
```
|
||||||
13
src/lib.rs
13
src/lib.rs
|
|
@ -7,6 +7,19 @@ use warp::Filter;
|
||||||
///
|
///
|
||||||
/// This uses the "x-forwarded-for" or "x-real-ip" headers set by reverse proxies.
|
/// 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.
|
/// To stop clients from abusing these headers, only headers set by trusted remotes will be accepted.
|
||||||
|
///
|
||||||
|
/// ## Example
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// 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()));
|
||||||
|
/// ```
|
||||||
pub fn real_ip(
|
pub fn real_ip(
|
||||||
trusted_proxies: Vec<IpAddr>,
|
trusted_proxies: Vec<IpAddr>,
|
||||||
) -> impl Filter<Extract = (Option<IpAddr>,), Error = Infallible> + Clone {
|
) -> impl Filter<Extract = (Option<IpAddr>,), Error = Infallible> + Clone {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue