pub struct RateLimitLayer;Expand description
Built-in middleware that enforces the process-wide rate limit
(configured via RWS_CONFIG_RATE_LIMIT_MAX_REQUESTS and
RWS_CONFIG_RATE_LIMIT_WINDOW_SECS).
Returns 429 Too Many Requests when the sliding-window budget for the
client IP is exhausted; otherwise passes the request to the next layer.
§Example
use rust_web_server::app::App;
use rust_web_server::middleware::{WithMiddleware, RateLimitLayer};
use rust_web_server::core::New;
let app = App::new().wrap(RateLimitLayer);Trait Implementations§
Source§impl Middleware for RateLimitLayer
impl Middleware for RateLimitLayer
Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
Headers only: a streamed body passes through untouched.
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
In-memory only: safe on the event loop.
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Auto Trait Implementations§
impl Freeze for RateLimitLayer
impl RefUnwindSafe for RateLimitLayer
impl Send for RateLimitLayer
impl Sync for RateLimitLayer
impl Unpin for RateLimitLayer
impl UnsafeUnpin for RateLimitLayer
impl UnwindSafe for RateLimitLayer
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