[−][src]Struct actix_ratelimit::middleware::RateLimiter
Type that implements the ratelimit middleware.
This accepts interval which specifies the window size, max_requests which specifies the maximum number of requests in that window, and store which is essentially a data store used to store client access information. Entry is removed from the store after interval.
Example
use actix_ratelimit::{MemoryStore, MemoryStoreActor}; use actix_ratelimit::RateLimiter; #[actix_rt::main] async fn main() { let store = MemoryStore::new(); let ratelimiter = RateLimiter::new( MemoryStoreActor::from(store.clone()).start()) .with_interval(Duration::from_secs(60)) .with_max_requests(100); }
Methods
impl<T> RateLimiter<T> where
T: Handler<ActorMessage> + Send + Sync + 'static,
<T as Actor>::Context: ToEnvelope<T, ActorMessage>,
[src]
T: Handler<ActorMessage> + Send + Sync + 'static,
<T as Actor>::Context: ToEnvelope<T, ActorMessage>,
pub fn new(store: Addr<T>) -> Self
[src]
Creates a new instance of RateLimiter
with the provided address of StoreActor
.
pub fn with_interval(self, interval: Duration) -> Self
[src]
Specify the interval. The counter for a client is reset after this interval
pub fn with_max_requests(self, max_requests: usize) -> Self
[src]
Specify the maximum number of requests allowed in the given interval.
pub fn with_identifier<F: Fn(&ServiceRequest) -> Result<String, ARError> + 'static>(
self,
identifier: F
) -> Self
[src]
self,
identifier: F
) -> Self
Function to get the identifier for the client request
Trait Implementations
impl<T, S, B> Transform<S> for RateLimiter<T> where
T: Handler<ActorMessage> + Send + Sync + 'static,
T::Context: ToEnvelope<T, ActorMessage>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = AWError> + 'static,
S::Future: 'static,
B: 'static,
[src]
T: Handler<ActorMessage> + Send + Sync + 'static,
T::Context: ToEnvelope<T, ActorMessage>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = AWError> + 'static,
S::Future: 'static,
B: 'static,
type Request = ServiceRequest
Requests handled by the service.
type Response = ServiceResponse<B>
Responses given by the service.
type Error = S::Error
Errors produced by the service.
type InitError = ()
Errors produced while building a transform service.
type Transform = RateLimitMiddleware<S, T>
The TransformService
value created by this factory
type Future = Ready<Result<Self::Transform, Self::InitError>>
The future response value.
fn new_transform(&self, service: S) -> Self::Future
[src]
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E> where
F: Fn(Self::InitError) -> E + Clone,
F: Fn(Self::InitError) -> E + Clone,
Auto Trait Implementations
impl<T> !RefUnwindSafe for RateLimiter<T>
impl<T> !Send for RateLimiter<T>
impl<T> !Sync for RateLimiter<T>
impl<T> Unpin for RateLimiter<T>
impl<T> !UnwindSafe for RateLimiter<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,