pub enum KeyExtractor {
XForwardedFor,
Header(HeaderName),
}Expand description
Determines how a per-client key is extracted from the request.
The key is used to track and limit each client independently. If the configured header is absent the request passes through without being counted.
§Examples
use http::HeaderName;
use rune_axum_ratelimit::KeyExtractor;
// Rate-limit by the first IP in X-Forwarded-For (set by most reverse proxies)
let by_ip = KeyExtractor::XForwardedFor;
// Rate-limit by an API key sent in a custom header
let by_key = KeyExtractor::Header(HeaderName::from_static("x-api-key"));Variants§
XForwardedFor
Uses the first (leftmost) IP in the X-Forwarded-For header.
[!WARNING] Clients can spoof this header unless your reverse proxy strips and re-adds it. Configure your proxy to overwrite
X-Forwarded-Forwith the true client IP.
Header(HeaderName)
Uses the value of a named request header as the client key.
Suitable for API key–based rate limiting: pass the header that carries the key,
e.g. HeaderName::from_static("x-api-key").
Trait Implementations§
Source§impl Clone for KeyExtractor
impl Clone for KeyExtractor
Source§fn clone(&self) -> KeyExtractor
fn clone(&self) -> KeyExtractor
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 moreAuto Trait Implementations§
impl !Freeze for KeyExtractor
impl RefUnwindSafe for KeyExtractor
impl Send for KeyExtractor
impl Sync for KeyExtractor
impl Unpin for KeyExtractor
impl UnsafeUnpin for KeyExtractor
impl UnwindSafe for KeyExtractor
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