pub struct RateLimitMiddleware { /* private fields */ }Expand description
Rate limiting middleware for PJS endpoints
Uses token bucket algorithm from security::rate_limit module Returns 429 Too Many Requests when limit exceeded Adds X-RateLimit-* headers per RFC 6585
Implementations§
Source§impl RateLimitMiddleware
impl RateLimitMiddleware
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Build a fresh middleware with its own internal WebSocketRateLimiter.
Spawns a background task that periodically prunes expired per-IP
entries (see crate::security::rate_limit::WebSocketRateLimiter::spawn_cleanup_task)
if called from within a Tokio runtime; otherwise construction still
succeeds, but periodic pruning is skipped with a logged warning.
Sourcepub fn from_limiter(limiter: Arc<WebSocketRateLimiter>) -> Self
pub fn from_limiter(limiter: Arc<WebSocketRateLimiter>) -> Self
Wrap an externally constructed WebSocketRateLimiter (lets several middlewares share state).
Spawns a background cleanup task via
crate::security::rate_limit::WebSocketRateLimiter::spawn_cleanup_task,
which is a no-op if one is already running for this limiter (e.g.
because another RateLimitMiddleware already wraps the same Arc).
Sourcepub fn with_trusted_proxies(self, config: TrustedProxyConfig) -> Self
pub fn with_trusted_proxies(self, config: TrustedProxyConfig) -> Self
Opt in to trusting X-Forwarded-For/X-Real-IP from the given proxy allowlist.
Trait Implementations§
Source§impl Clone for RateLimitMiddleware
impl Clone for RateLimitMiddleware
Source§fn clone(&self) -> RateLimitMiddleware
fn clone(&self) -> RateLimitMiddleware
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RateLimitMiddleware
impl !UnwindSafe for RateLimitMiddleware
impl Freeze for RateLimitMiddleware
impl Send for RateLimitMiddleware
impl Sync for RateLimitMiddleware
impl Unpin for RateLimitMiddleware
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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