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(
|
let app = actix_web::test::init_service(
|
||||||
actix_web::App::new()
|
actix_web::App::new()
|
||||||
.wrap(RateLimiter {
|
.wrap(RateLimiter::scoped("default"))
|
||||||
scope: Some("default"),
|
|
||||||
})
|
|
||||||
.app_data(limiters.clone())
|
.app_data(limiters.clone())
|
||||||
.service(
|
.service(
|
||||||
web::scope("/scoped")
|
web::scope("/scoped")
|
||||||
.wrap(RateLimiter {
|
.wrap(RateLimiter::scoped("scoped"))
|
||||||
scope: Some("scoped"),
|
|
||||||
})
|
|
||||||
.service(index),
|
.service(index),
|
||||||
)
|
)
|
||||||
.service(index),
|
.service(index),
|
||||||
|
@ -22,6 +22,13 @@ pub struct RateLimiter {
|
|||||||
pub scope: Option<&'static str>,
|
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
|
impl<S, B> Transform<S, ServiceRequest> for RateLimiter
|
||||||
where
|
where
|
||||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
|
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user