Crate rocket_governor[][src]

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.

Example

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 {
        Quota::per_second(Self::nonzero(1u32))
    }
}

#[get("/")]
fn route_example(_limitguard: RocketGovernor<RateLimitGuard>) -> Status {
    Status::Ok
}

#[launch]
fn launch_rocket() -> _ {
    rocket::build()
        .mount("/", routes![route_example])
        .register("/", catchers![rocket_governor_catcher])
}

See rocket-governor Github project for more information.

Features

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

For usage depend on it in Cargo.toml

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

Modules

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

Structs

An integer that is known not to equal zero.

A rate-limiting quota.

Generic RocketGovernor implementation.

Enums

Errors for governed requests which implement Responder.

Representation of HTTP methods.

Traits

Functions

A default implementation for Rocket Catcher handling HTTP TooManyRequests responses.