pub struct RateLimitMiddleware { /* private fields */ }Expand description
Rate limiting middleware
Uses the governor crate’s GCRA implementation to enforce rate limits per client IP address. When a client exceeds their rate limit, a 429 response is returned immediately without forwarding to the upstream.
Implementations§
Source§impl RateLimitMiddleware
impl RateLimitMiddleware
Sourcepub fn new(enabled: bool, requests_per_sec: u32, burst_size: u32) -> Self
pub fn new(enabled: bool, requests_per_sec: u32, burst_size: u32) -> Self
Create a new rate limiting middleware
§Arguments
enabled- Whether to enable rate limitingrequests_per_sec- Maximum requests per second per IPburst_size- Maximum burst size (tokens available immediately)
§Example
use warpdrive::middleware::RateLimitMiddleware;
// Allow 10 req/s with burst of 20
let middleware = RateLimitMiddleware::new(true, 10, 20);Trait Implementations§
Source§impl Middleware for RateLimitMiddleware
impl Middleware for RateLimitMiddleware
Source§fn request_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
ctx: &'life2 mut MiddlewareContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn request_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session: &'life1 mut Session,
ctx: &'life2 mut MiddlewareContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Process request before sending to upstream
Source§fn response_filter<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_session: &'life1 mut Session,
_upstream_response: &'life2 mut ResponseHeader,
_ctx: &'life3 mut MiddlewareContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn response_filter<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_session: &'life1 mut Session,
_upstream_response: &'life2 mut ResponseHeader,
_ctx: &'life3 mut MiddlewareContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Process response before sending to client
Auto Trait Implementations§
impl Freeze for RateLimitMiddleware
impl !RefUnwindSafe for RateLimitMiddleware
impl Send for RateLimitMiddleware
impl Sync for RateLimitMiddleware
impl Unpin for RateLimitMiddleware
impl !UnwindSafe for RateLimitMiddleware
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