pub struct RateLimitConfig { /* private fields */ }Expand description
Configuration for the rate limiter middleware.
Build with RateLimitConfig::new() and chain methods to set the request limit,
window duration, rejection status, and key extraction strategy. Then pass to
RateLimitLayer::new().
§Examples
use std::time::Duration;
use http::StatusCode;
use rune_axum_ratelimit::RateLimitConfig;
let config = RateLimitConfig::new()
.requests(50)
.window(Duration::from_secs(30))
.status(StatusCode::TOO_MANY_REQUESTS);Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn new() -> RateLimitConfig
pub fn new() -> RateLimitConfig
Creates a RateLimitConfig with defaults: 100 req/60 s, X-Forwarded-For keying,
429 Too Many Requests rejection.
Sourcepub fn requests(self, n: u64) -> RateLimitConfig
pub fn requests(self, n: u64) -> RateLimitConfig
Sets the maximum number of requests allowed per window per client.
Defaults to 100.
Sourcepub fn window(self, d: Duration) -> RateLimitConfig
pub fn window(self, d: Duration) -> RateLimitConfig
Sets the duration of each fixed window.
Defaults to 60 seconds.
Sourcepub fn status(self, s: StatusCode) -> RateLimitConfig
pub fn status(self, s: StatusCode) -> RateLimitConfig
Sets the HTTP status code returned when the limit is exceeded.
Defaults to 429 Too Many Requests.
Sourcepub fn key(self, k: KeyExtractor) -> RateLimitConfig
pub fn key(self, k: KeyExtractor) -> RateLimitConfig
Sets the strategy used to identify each client.
Defaults to KeyExtractor::XForwardedFor.
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateLimitConfig
impl Debug for RateLimitConfig
Source§impl Default for RateLimitConfig
impl Default for RateLimitConfig
Source§fn default() -> RateLimitConfig
fn default() -> RateLimitConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for RateLimitConfig
impl RefUnwindSafe for RateLimitConfig
impl Send for RateLimitConfig
impl Sync for RateLimitConfig
impl Unpin for RateLimitConfig
impl UnsafeUnpin for RateLimitConfig
impl UnwindSafe for RateLimitConfig
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