mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-22 18:33:18 +01:00
feat(limitation): limiter with scope function
This commit is contained in:
parent
4006a49274
commit
fb657e0336
@ -232,15 +232,11 @@ mod tests {
|
||||
|
||||
let app = actix_web::test::init_service(
|
||||
actix_web::App::new()
|
||||
.wrap(RateLimiter {
|
||||
scope: Some("default"),
|
||||
})
|
||||
.wrap(RateLimiter::scoped("default"))
|
||||
.app_data(limiters.clone())
|
||||
.service(
|
||||
web::scope("/scoped")
|
||||
.wrap(RateLimiter {
|
||||
scope: Some("scoped"),
|
||||
})
|
||||
.wrap(RateLimiter::scoped("scoped"))
|
||||
.service(index),
|
||||
)
|
||||
.service(index),
|
||||
|
@ -22,6 +22,13 @@ pub struct RateLimiter {
|
||||
pub scope: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl RateLimiter {
|
||||
/// Construct the rate limiter with a scope
|
||||
pub fn scoped(scope: &'static str) -> Self {
|
||||
RateLimiter { scope: Some(scope) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, B> Transform<S, ServiceRequest> for RateLimiter
|
||||
where
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
|
||||
|
Loading…
x
Reference in New Issue
Block a user