pub struct Throttle { /* private fields */ }Expand description
Limits how often one client may hit the routes it guards.
Implementations§
Source§impl Throttle
impl Throttle
Sourcepub fn new(cache: &CacheStore, max: u64, window: Duration) -> Self
pub fn new(cache: &CacheStore, max: u64, window: Duration) -> Self
max requests per window, keyed by client IP and route.
Sourcepub fn per_minute(cache: &CacheStore, max: u64) -> Self
pub fn per_minute(cache: &CacheStore, max: u64) -> Self
The common case, and the one Laravel spells throttle:60,1.
pub fn per_second(cache: &CacheStore, max: u64) -> Self
Sourcepub fn with_driver(store: Arc<dyn Cache>, max: u64, window: Duration) -> Self
pub fn with_driver(store: Arc<dyn Cache>, max: u64, window: Duration) -> Self
Build directly on a driver, for tests and for callers that never made a
CacheStore.
Sourcepub fn by(
self,
key: impl Fn(&Request) -> String + Send + Sync + 'static,
) -> Self
pub fn by( self, key: impl Fn(&Request) -> String + Send + Sync + 'static, ) -> Self
Key the bucket by something other than the client IP: an API token, a tenant, an authenticated user id.
Worth doing whenever requests arrive through a NAT or a mobile carrier, where thousands of unrelated users share one address.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Throttle
impl !UnwindSafe for Throttle
impl Freeze for Throttle
impl Send for Throttle
impl Sync for Throttle
impl Unpin for Throttle
impl UnsafeUnpin for Throttle
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