pub struct RateLimiterBuilder<BE, BO, F> { /* private fields */ }
Implementations§
Source§impl<BE, BI, BO, F, O> RateLimiterBuilder<BE, BO, F>
impl<BE, BI, BO, F, O> RateLimiterBuilder<BE, BO, F>
Sourcepub fn fail_open(self, fail_open: bool) -> Self
pub fn fail_open(self, fail_open: bool) -> Self
Choose whether to allow a request if the backend returns a failure.
Default is false.
Sourcepub fn add_headers(self) -> Selfwhere
BO: HeaderCompatibleOutput,
pub fn add_headers(self) -> Selfwhere
BO: HeaderCompatibleOutput,
Sets the RateLimiterBuilder::request_allowed_transformation and RateLimiterBuilder::request_denied_response functions, such that the following headers are set in both the allowed and denied responses:
x-ratelimit-limit
\x-ratelimit-remaining
\x-ratelimit-reset
(seconds until the reset)retry-after
(denied only, seconds until the reset)
This function requires the Backend Output to implement HeaderCompatibleOutput
Sourcepub fn request_allowed_transformation<M>(self, mutation: Option<M>) -> Self
pub fn request_allowed_transformation<M>(self, mutation: Option<M>) -> Self
In the event that the request is allowed:
You can optionally mutate the response headers to include the rate limit status.
By default no changes are made to the response.
Note the Backend::Output will be None if the backend failed and RateLimiterBuilder::fail_open is enabled.
The boolean parameter indicates if the rate limit was rolled back (so the remaining request count can be adjusted).
Sourcepub fn request_denied_response<R>(self, denied_response: R) -> Self
pub fn request_denied_response<R>(self, denied_response: R) -> Self
In the event that the request is denied, configure the HttpResponse returned.
Defaults to an empty body with status 429.
Sourcepub fn rollback_condition<C>(self, condition: Option<C>) -> Self
pub fn rollback_condition<C>(self, condition: Option<C>) -> Self
After processing a request, attempt to rollback the request count based on the status of the service response.
By default the rate limit is never rolled back.
Sourcepub fn rollback_server_errors(self) -> Self
pub fn rollback_server_errors(self) -> Self
Configures the RateLimiterBuilder::rollback_condition to rollback if the status code is a server error (5xx).
pub fn build(self) -> RateLimiter<BE, BO, F>
Auto Trait Implementations§
impl<BE, BO, F> Freeze for RateLimiterBuilder<BE, BO, F>
impl<BE, BO, F> !RefUnwindSafe for RateLimiterBuilder<BE, BO, F>
impl<BE, BO, F> !Send for RateLimiterBuilder<BE, BO, F>
impl<BE, BO, F> !Sync for RateLimiterBuilder<BE, BO, F>
impl<BE, BO, F> Unpin for RateLimiterBuilder<BE, BO, F>
impl<BE, BO, F> !UnwindSafe for RateLimiterBuilder<BE, BO, F>
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
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