Allow specifying IP networks for permitted proxies in place of IP addresses.

This commit is contained in:
Moriyoshi Koizumi 2021-07-12 09:53:29 +09:00
commit c6af4e7ae9
4 changed files with 45 additions and 5 deletions

View file

@ -1,10 +1,10 @@
use std::net::IpAddr;
use warp::Filter;
use warp_real_ip::real_ip;
use warp_real_ip::{IpNetworks, real_ip};
fn serve<'a>(trusted: Vec<IpAddr>) -> impl Filter<Extract = (String,)> + 'a {
warp::any()
.and(real_ip(trusted))
.and(real_ip(IpNetworks::from_ipaddr_iter(trusted.iter())))
.map(|addr: Option<IpAddr>| addr.unwrap().to_string())
}