2 releases
0.1.1 | Oct 20, 2019 |
---|---|
0.1.0 | Oct 20, 2019 |
#14 in #actix-middleware
Used in limitation-proxy
73KB
494 lines
limitation-actix-middleware
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.
Usage
Add limitation-actix-middleware
to your Cargo.toml
:
[dependencies]
limitation-actix-middleware = "0.1.1"
Quick Example
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:
- A
HeaderName
which is the header to use as the rate limiter key - A
Limiter
which performs the rate limiting and manages persistence
use 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()))
);
Examples
This crate ships with an example program called catchall which can be run from the sources with:
$ cargo run --example catchall
CI Status
Build (master branch)
Operating System | Stable Rust | Nightly Rust | MSRV |
---|---|---|---|
FreeBSD | |||
Linux | |||
macOS | |||
Windows |
Test (master branch)
Operating System | Stable Rust | Nightly Rust | MSRV |
---|---|---|---|
FreeBSD | |||
Linux | |||
macOS | |||
Windows |
Check (master branch)
Status | |
---|---|
Lint | |
Format |
Code of Conduct
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.
Issues
If you have any problems with or questions about this project, please contact us through a GitHub issue.
Contributing
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.
Release History
See the changelog for a full release history.
Authors
Created and maintained by Fletcher Nichol (fnichol@nichol.ca).
License
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.
Dependencies
~28MB
~574K SLoC