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 + Sync + Send>>,
}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 + Sync + Send>>Custom error response
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn new() -> RateLimitConfig
pub fn new() -> RateLimitConfig
Create a new rate limit configuration.
Sourcepub fn max_requests(self, max: u64) -> RateLimitConfig
pub fn max_requests(self, max: u64) -> RateLimitConfig
Set maximum requests per window.
Sourcepub fn requests_per_second(self, rps: u64) -> RateLimitConfig
pub fn requests_per_second(self, rps: u64) -> RateLimitConfig
Set requests per second (convenience method).
Sourcepub fn requests_per_minute(self, rpm: u64) -> RateLimitConfig
pub fn requests_per_minute(self, rpm: u64) -> RateLimitConfig
Set requests per minute.
Sourcepub fn window(self, window: Duration) -> RateLimitConfig
pub fn window(self, window: Duration) -> RateLimitConfig
Set time window.
Sourcepub fn burst_size(self, size: u64) -> RateLimitConfig
pub fn burst_size(self, size: u64) -> RateLimitConfig
Set burst size for token bucket algorithm.
Sourcepub fn algorithm(self, algo: RateLimitAlgorithm) -> RateLimitConfig
pub fn algorithm(self, algo: RateLimitAlgorithm) -> RateLimitConfig
Set the rate limiting algorithm.
Sourcepub fn key_extractor(self, extractor: KeyExtractor) -> RateLimitConfig
pub fn key_extractor(self, extractor: KeyExtractor) -> RateLimitConfig
Set the key extractor.
Sourcepub fn exclude_paths(self, paths: Vec<&str>) -> RateLimitConfig
pub fn exclude_paths(self, paths: Vec<&str>) -> RateLimitConfig
Exclude paths from rate limiting.
Sourcepub fn add_headers(self, add: bool) -> RateLimitConfig
pub fn add_headers(self, add: bool) -> RateLimitConfig
Whether to add rate limit headers.
Sourcepub fn error_response<F>(self, handler: F) -> RateLimitConfig
pub fn error_response<F>(self, handler: F) -> RateLimitConfig
Set custom error response handler.
Sourcepub fn strict_login() -> RateLimitConfig
pub fn strict_login() -> RateLimitConfig
Create a strict configuration for login endpoints.
Sourcepub fn lenient_api() -> RateLimitConfig
pub fn lenient_api() -> RateLimitConfig
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
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 !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