pub struct IpKeyExtractor;Expand description
Rate limit by client IP address from X-Forwarded-For or X-Real-IP headers.
§Security Warning
This extractor trusts client-supplied headers, which can be spoofed!
Only use this extractor when:
- Your application runs behind a trusted reverse proxy (nginx, Cloudflare, etc.)
- The proxy is configured to set/override these headers
- Clients cannot connect directly to your application
For direct client connections, use ConnectedIpKeyExtractor instead.
§How Proxies Work
When a request passes through proxies:
X-Forwarded-For: client_ip, proxy1_ip, proxy2_ip- The first IP is typically the original client
- Each proxy appends its own IP
This extractor takes the first IP from X-Forwarded-For, which is correct
only if your trusted proxy always sets/overwrites this header.
§Fallback Behavior
Falls back to "unknown" when no IP header is present, which means all such
requests share the same rate limit bucket. This may not be desirable in
production - consider using TrustedProxyIpKeyExtractor for better control.
Trait Implementations§
Source§impl Clone for IpKeyExtractor
impl Clone for IpKeyExtractor
Source§fn clone(&self) -> IpKeyExtractor
fn clone(&self) -> IpKeyExtractor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for IpKeyExtractor
impl Debug for IpKeyExtractor
Source§impl KeyExtractor for IpKeyExtractor
impl KeyExtractor for IpKeyExtractor
Auto Trait Implementations§
impl Freeze for IpKeyExtractor
impl RefUnwindSafe for IpKeyExtractor
impl Send for IpKeyExtractor
impl Sync for IpKeyExtractor
impl Unpin for IpKeyExtractor
impl UnwindSafe for IpKeyExtractor
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).