pub struct TrustedProxies { /* private fields */ }Expand description
Reverse proxies whose forwarding header is believed, and which header that is.
Empty by default: the client IP is then always the TCP peer. Behind a
reverse proxy, list its address (or range), otherwise every client shares
the proxy’s bucket. Only the configured ClientIpHeader is read,
X-Forwarded-For unless TrustedProxies::with_header says otherwise.
Parsed from a comma-separated list of IP addresses and CIDR ranges.
§Examples
use ironflow_api::rate_limit::TrustedProxies;
let proxies: TrustedProxies = "10.0.0.0/8, 192.168.1.10".parse()?;
assert!(proxies.contains("10.1.2.3".parse()?));
assert!(proxies.contains("192.168.1.10".parse()?));
assert!(!proxies.contains("203.0.113.7".parse()?));
assert!(TrustedProxies::default().is_empty());Implementations§
Source§impl TrustedProxies
impl TrustedProxies
Sourcepub fn contains(&self, ip: IpAddr) -> bool
pub fn contains(&self, ip: IpAddr) -> bool
Whether ip belongs to one of the trusted proxies.
An IPv4-mapped IPv6 address (::ffff:10.0.0.1) matches its IPv4 form.
§Examples
use ironflow_api::rate_limit::TrustedProxies;
let proxies: TrustedProxies = "10.0.0.1".parse()?;
assert!(proxies.contains("::ffff:10.0.0.1".parse()?));Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether no proxy is trusted.
§Examples
use ironflow_api::rate_limit::TrustedProxies;
assert!(TrustedProxies::default().is_empty());Sourcepub fn with_header(self, header: ClientIpHeader) -> Self
pub fn with_header(self, header: ClientIpHeader) -> Self
Read the client IP from header instead of the default
X-Forwarded-For.
§Examples
use ironflow_api::rate_limit::{ClientIpHeader, TrustedProxies};
let proxies = "10.0.0.1"
.parse::<TrustedProxies>()?
.with_header(ClientIpHeader::XRealIp);
assert_eq!(proxies.header(), ClientIpHeader::XRealIp);Sourcepub fn header(&self) -> ClientIpHeader
pub fn header(&self) -> ClientIpHeader
The forwarding header read from a trusted proxy.
§Examples
use ironflow_api::rate_limit::{ClientIpHeader, TrustedProxies};
assert_eq!(TrustedProxies::default().header(), ClientIpHeader::XForwardedFor);Trait Implementations§
Source§impl Clone for TrustedProxies
impl Clone for TrustedProxies
Source§impl Debug for TrustedProxies
impl Debug for TrustedProxies
Source§impl Default for TrustedProxies
impl Default for TrustedProxies
impl Eq for TrustedProxies
Source§impl FromStr for TrustedProxies
impl FromStr for TrustedProxies
Source§impl PartialEq for TrustedProxies
impl PartialEq for TrustedProxies
impl StructuralPartialEq for TrustedProxies
Auto Trait Implementations§
impl Freeze for TrustedProxies
impl RefUnwindSafe for TrustedProxies
impl Send for TrustedProxies
impl Sync for TrustedProxies
impl Unpin for TrustedProxies
impl UnsafeUnpin for TrustedProxies
impl UnwindSafe for TrustedProxies
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.