Crates.io | limitation-actix-middleware |
lib.rs | limitation-actix-middleware |
version | 0.1.1 |
source | src |
created_at | 2019-10-20 20:52:47.043839 |
updated_at | 2019-10-20 21:19:11.866825 |
description | An Actix web middleware for rate limiting requests using a fixed window counter keyed on a header. |
homepage | |
repository | https://github.com/fnichol/limitation |
max_upload_size | |
id | 174323 |
size | 144,012 |
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
:
[dependencies]
limitation-actix-middleware = "0.1.1"
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 persistenceuse actix_web::{http::header::HeaderName, web, App, HttpResponse};
use limitation_actix_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
.register_data(header.clone())
// Register the Limiter as application data
.register_data(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:
$ 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.