Actix Extensible Rate Limit
An attempt at a more flexible rate limiting middleware for actix-web
Allows for:
- Deriving a custom rate limit key from the request context.
- Using dynamic rate limits and intervals determined by the request context.
- Using custom backends (store & algorithm)
- Setting a custom 429 response.
- Transforming the response headers based on rate limit results (e.g
x-ratelimit-remaining). - Rolling back rate limit counts based on response codes.
Provided Backends
| Backend | Algorithm | Store |
|---|---|---|
| InMemoryBackend | Fixed Window | Dashmap |
| RedisBackend | Fixed Window | Redis |
Getting Started
use ;
use ;
use Duration;
async
Try it out:
$ curl -v http://127.0.0.1:8080
* Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< content-length: 0
< x-ratelimit-limit: 5
< x-ratelimit-reset: 60
< x-ratelimit-remaining: 4
< date: Sun, 21 Jan 2024 16:52:27 GMT
<
* Connection #0 to host 127.0.0.1 left intact