pub struct RateLimitConfig {
pub max_requests: u64,
pub window: Duration,
pub burst_size: u64,
pub algorithm: RateLimitAlgorithm,
pub key_extractor: KeyExtractor,
pub excluded_paths: Vec<String>,
pub add_headers: bool,
pub error_response: Option<Arc<dyn Fn(RateLimitExceeded) -> HttpResponse + Send + Sync>>,
}Expand description
Rate limit configuration.
Fields§
§max_requests: u64Maximum requests per window
window: DurationTime window duration
burst_size: u64Burst size (for token bucket)
algorithm: RateLimitAlgorithmAlgorithm to use
key_extractor: KeyExtractorKey extractor
excluded_paths: Vec<String>Paths to exclude from rate limiting
add_headers: boolWhether to add rate limit headers to response
error_response: Option<Arc<dyn Fn(RateLimitExceeded) -> HttpResponse + Send + Sync>>Custom error response
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn max_requests(self, max: u64) -> Self
pub fn max_requests(self, max: u64) -> Self
Set maximum requests per window.
Sourcepub fn requests_per_second(self, rps: u64) -> Self
pub fn requests_per_second(self, rps: u64) -> Self
Set requests per second (convenience method).
Sourcepub fn requests_per_minute(self, rpm: u64) -> Self
pub fn requests_per_minute(self, rpm: u64) -> Self
Set requests per minute.
Sourcepub fn burst_size(self, size: u64) -> Self
pub fn burst_size(self, size: u64) -> Self
Set burst size for token bucket algorithm.
Sourcepub fn algorithm(self, algo: RateLimitAlgorithm) -> Self
pub fn algorithm(self, algo: RateLimitAlgorithm) -> Self
Set the rate limiting algorithm.
Sourcepub fn key_extractor(self, extractor: KeyExtractor) -> Self
pub fn key_extractor(self, extractor: KeyExtractor) -> Self
Set the key extractor.
Sourcepub fn exclude_paths(self, paths: Vec<&str>) -> Self
pub fn exclude_paths(self, paths: Vec<&str>) -> Self
Exclude paths from rate limiting.
Sourcepub fn add_headers(self, add: bool) -> Self
pub fn add_headers(self, add: bool) -> Self
Whether to add rate limit headers.
Sourcepub fn error_response<F>(self, handler: F) -> Self
pub fn error_response<F>(self, handler: F) -> Self
Set custom error response handler.
Sourcepub fn strict_login() -> Self
pub fn strict_login() -> Self
Create a strict configuration for login endpoints.
Sourcepub fn lenient_api() -> Self
pub fn lenient_api() -> Self
Create a lenient configuration for API endpoints.
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
Auto Trait Implementations§
impl Freeze for RateLimitConfig
impl !RefUnwindSafe for RateLimitConfig
impl Send for RateLimitConfig
impl Sync for RateLimitConfig
impl Unpin 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
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>
Converts
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>
Converts
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