Trait actix_extensible_rate_limit::backend::Backend
source · pub trait Backend<I: 'static = SimpleInput>: Clone {
type Output;
type RollbackToken;
type Error;
// Required methods
fn request(
&self,
input: I
) -> impl Future<Output = Result<(Decision, Self::Output, Self::RollbackToken), Self::Error>>;
fn rollback(
&self,
token: Self::RollbackToken
) -> impl Future<Output = Result<(), Self::Error>>;
}
Expand description
Required Associated Types§
Required Methods§
sourcefn request(
&self,
input: I
) -> impl Future<Output = Result<(Decision, Self::Output, Self::RollbackToken), Self::Error>>
fn request( &self, input: I ) -> impl Future<Output = Result<(Decision, Self::Output, Self::RollbackToken), Self::Error>>
Process an incoming request.
The input could include such things as a rate limit key, and the rate limit policy to be applied.
Returns a boolean of whether to allow or deny the request, arbitrary output that can be used to transform the allowed and denied responses, and a token to allow the rate limit counter to be rolled back in certain conditions.
sourcefn rollback(
&self,
token: Self::RollbackToken
) -> impl Future<Output = Result<(), Self::Error>>
fn rollback( &self, token: Self::RollbackToken ) -> impl Future<Output = Result<(), Self::Error>>
Under certain conditions we may not want to rollback the request operation.
E.g. We may want to exclude 5xx errors from counting against a user’s rate limit, we can only exclude them after having already allowed the request through the rate limiter in the first place, so we must therefore deduct from the rate limit counter afterwards.
Note that if this function fails there is not much the RateLimiter can do about it, given that the request has already been allowed.
Arguments
token
: The token returned from the initial call to Backend::request().