pub struct RateLimitHoop { /* private fields */ }Expand description
Per-IP rate limiting middleware using a token bucket algorithm.
Each client IP gets a bucket that starts at burst tokens and is
replenished at a rate of max_tokens / window per second, capped at
burst. If a request arrives and the bucket is empty, a 429 Too Many
Requests response is returned.
burst defaults to max_tokens when not specified, which matches the
previous behaviour.
Implementations§
Source§impl RateLimitHoop
impl RateLimitHoop
Sourcepub fn new(window: Duration, max_requests: u64, burst: Option<u64>) -> Self
pub fn new(window: Duration, max_requests: u64, burst: Option<u64>) -> Self
Create a new rate limiter.
window— the time window over whichmax_requestsapplies.max_requests— steady-state refill rate (tokens per window).burst— maximum token bucket capacity;Nonedefaults tomax_requests(pre-existing behaviour).
Trait Implementations§
Source§impl Handler for RateLimitHoop
impl Handler for RateLimitHoop
Source§fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
req: &'life1 mut Request,
depot: &'life2 mut Depot,
res: &'life3 mut Response,
ctrl: &'life4 mut FlowCtrl,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Handle http request.
Source§fn arc(self) -> ArcHandlerwhere
Self: Sized,
fn arc(self) -> ArcHandlerwhere
Self: Sized,
Wrap to
ArcHandler.Source§fn hoop<H>(self, hoop: H) -> HoopedHandler
fn hoop<H>(self, hoop: H) -> HoopedHandler
Hoop this handler with middleware.
Auto Trait Implementations§
impl Freeze for RateLimitHoop
impl !RefUnwindSafe for RateLimitHoop
impl Send for RateLimitHoop
impl Sync for RateLimitHoop
impl Unpin for RateLimitHoop
impl UnsafeUnpin for RateLimitHoop
impl !UnwindSafe for RateLimitHoop
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
Mutably borrows from an owned value. Read more