| | |
| --------------: | ------------------------------------------- |
| CI | |
| Latest Version |
|
| Documentation |
|
| Crate Downloads |
|
| License |
|
Table of Contents
An Actix web middleware for rate limiting requests using a fixed window counter keyed on a header.
Add limitation-actix-middleware
to your Cargo.toml
:
toml
[dependencies]
limitation-actix-middleware = "0.1.0"
The [RateLimiter
] middleware is the primary type which is intended to be
inserted in an Actix web app's middleware chain. The middleware requires 2
Data
types to be present:
HeaderName
which is the header to use as the rate limiter keyLimiter
] which performs the rate limiting and manages persistence```rust use actixweb::{http::header::HeaderName, web, App, HttpResponse}; use limitationactix_middleware::{Limiter, RateLimiter};
// Choose a header to use for rate limit tracking
let header = web::Data::new(HeaderName::from_static("authorization"));
// Build a Limiter
which will be used by the middleware
let limiter = web::Data::new(Limiter::build("redis://127.0.0.1/").finish()?);
let app = App::new() // Register the header as application data .registerdata(header.clone()) // Register the Limiter as application data .registerdata(limiter.clone()) // Insert the RateLimter middleware .wrap(RateLimiter) .service( web::resource("/test") .route(web::get().to(|| HttpResponse::Ok())) .route(web::head().to(|| HttpResponse::MethodNotAllowed())) ); ```
This crate ships with an example program called [catchall] which can be run from the sources with:
console
$ cargo run --example catchall
| Operating System | Stable Rust | Nightly Rust | MSRV |
| ---------------: | ----------------------------------------------------------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| FreeBSD | |
|
|
| Linux |
|
|
|
| macOS |
|
|
|
| Windows |
|
|
|
| Operating System | Stable Rust | Nightly Rust | MSRV |
| ---------------: | --------------------------------------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------- |
| FreeBSD | |
|
|
| Linux |
|
|
|
| macOS |
|
|
|
| Windows |
|
|
|
| | Status |
| ------ | ------------------------------------------------- |
| Lint | |
| Format |
|
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to fnichol@nichol.ca.
If you have any problems with or questions about this project, please contact us through a GitHub issue.
You are invited to contribute to new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.
Before you start to code, we recommend discussing your plans through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.
See the [changelog] for a full release history.
Created and maintained by Fletcher Nichol (fnichol@nichol.ca).
Licensed under the Mozilla Public License Version 2.0 (LICENSE.txt).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MPL-2.0 license, shall be licensed as above, without any additional terms or conditions.