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).