pub struct Config { /* private fields */ }Expand description
Config for trusted proxies extractor
By default, it trusts the following:
- IPV4 Loopback
- IPV4 Private Networks
- IPV6 Loopback
- IPV6 Private Networks
It also trusts the FORWARDED and `X-Forwarded-For’ header by default.
§Example
use trusted_proxies::Config;
let mut config = Config::new_local();
config.add_trusted_ip("168.10.0.0/16").unwrap();
config.trust_x_forwarded_host();
Implementations§
Source§impl Config
impl Config
Sourcepub fn new_local() -> Self
pub fn new_local() -> Self
Create a new TrustedProxies instance with local and private networks ip trusted and FORWARDED / X-Forwarded-For headers trusted
Sourcepub fn add_trusted_ip(&mut self, proxy: &str) -> Result<(), AddrParseError>
pub fn add_trusted_ip(&mut self, proxy: &str) -> Result<(), AddrParseError>
Add a trusted proxy to the list of trusted proxies
proxy can be an IP address or a CIDR
Sourcepub fn is_ip_trusted(&self, remote_addr: &IpAddr) -> bool
pub fn is_ip_trusted(&self, remote_addr: &IpAddr) -> bool
Check if a remote address is trusted given the list of trusted proxies
pub fn trust_forwarded(&mut self)
pub fn trust_x_forwarded_for(&mut self)
pub fn trust_x_forwarded_host(&mut self)
pub fn trust_x_forwarded_proto(&mut self)
pub fn trust_x_forwarded_by(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more