Expand description

rocket-governor - rate-limiting implementation for Rocket web framework

Provides the rocket guard implementing rate-limiting (based on governor).

Declare a struct and use it with the generic RocketGovernor guard.
This requires to implement trait RocketGovernable for your struct.


use rocket::{catchers, get, http::Status, launch, routes};
use rocket_governor::{rocket_governor_catcher, Method, Quota, RocketGovernable, RocketGovernor};

pub struct RateLimitGuard;

impl<'r> RocketGovernable<'r> for RateLimitGuard {
    fn quota(_method: Method, _route_name: &str) -> Quota {

fn route_example(_limitguard: RocketGovernor<RateLimitGuard>) -> Status {

fn launch_rocket() -> _ {
        .mount("/", routes![route_example])
        .register("/", catchers![rocket_governor_catcher])

See rocket-governor Github project for more information.


Optional feature limit_info

There is the optional feature limit_info which enables reporting about rate limits in HTTP headers of requests.

The implementation is based on headers of https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers. The feature provides a default implementation of a Rocket fairing which need to be used to get the HTTP headers set.

See API documentation for LimitHeaderGen.

For usage depend on it in Cargo.toml

rocket-governor = { version = "...", features = ["limit_info"] }

Optional feature logger

There is the optional feature logger which enables some logging output.

For usage depend on it in Cargo.toml

rocket-governor = { version = "...", features = ["logger"] }


The headers used when a RocketGovernor guarded path responds with TooManyRequests.


Provides Fairing implementation which is attachable to Rocket-instance.

An integer that is known not to equal zero.

A rate-limiting quota.

ReqState is the data struct to handle information about Quota and limits in the Request state.

Generic RocketGovernor implementation.


Errors for governed requests which implement Responder.

Representation of HTTP methods.



A default implementation for Rocket Catcher handling HTTP TooManyRequests responses.