pub enum RateLimitKey {
Ip(IpAddr),
Header(String),
Route(Uuid),
Global,
}Expand description
Key for rate limiting: who a bucket is counting.
Variants§
Ip(IpAddr)
Rate limit by IP address. Build it with RateLimitKey::client_ip,
which groups an IPv6 client by its /64.
Header(String)
Rate limit by custom header value. Build it with
RateLimitKey::header_value, which stores a digest rather than the
value itself.
Route(Uuid)
Rate limit by route ID
Global
Global rate limit
Implementations§
Source§impl RateLimitKey
impl RateLimitKey
Sourcepub fn client_ip(ip: IpAddr) -> Self
pub fn client_ip(ip: IpAddr) -> Self
The key for a client connecting from ip.
An IPv6 client is keyed by its /64. A single host is normally handed a whole /64, and can pick any address in it for each connection; keyed by the full address, every request could come from a fresh bucket, which is the same as no limit at all.
An IPv4 client arriving on an IPv6 socket appears as ::ffff:a.b.c.d.
That is canonicalised back to IPv4 first, or every IPv4 client would
share the one /64 that holds all the mapped addresses.
Sourcepub fn header_value(value: &[u8]) -> Self
pub fn header_value(value: &[u8]) -> Self
The key for a header value.
A digest, not the value: header values are client-chosen and can be
kilobytes long, and the table holds up to
RateLimitDefaults::max_tracked_keys of them. It also keeps API keys
and the like out of the limiter’s memory.
Trait Implementations§
Source§impl Clone for RateLimitKey
impl Clone for RateLimitKey
Source§impl Debug for RateLimitKey
impl Debug for RateLimitKey
impl Eq for RateLimitKey
Source§impl Hash for RateLimitKey
impl Hash for RateLimitKey
Source§impl PartialEq for RateLimitKey
impl PartialEq for RateLimitKey
impl StructuralPartialEq for RateLimitKey
Auto Trait Implementations§
impl Freeze for RateLimitKey
impl RefUnwindSafe for RateLimitKey
impl Send for RateLimitKey
impl Sync for RateLimitKey
impl Unpin for RateLimitKey
impl UnsafeUnpin for RateLimitKey
impl UnwindSafe for RateLimitKey
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more