pub struct RateLimitConfig {
pub enabled: bool,
pub default: RateLimitRule,
pub trust_proxy_headers: bool,
pub cleanup_interval_secs: u64,
pub stale_after_secs: u64,
}Expand description
How many requests one client may make, before the API starts answering
429 Too Many Requests.
Off until asked for: default = "off" means an app that says nothing here
is limited nowhere, and an upgrade cannot start refusing traffic that used
to be served. Naming a rate switches it on for every endpoint at once:
[rate_limit]
default = "100/1m"A resource narrows or lifts that per action in its own [rate_limit]
section, and a function does the same with a rate_limit key in its
functions/<name>.toml — see crate::RateLimits.
§Who “one client” is
The peer socket address, which a caller cannot forge. Behind a reverse
proxy that is the proxy’s address for every request — one bucket for
everybody, throttling all callers together — so a deployment behind one has
to set trust_proxy_headers = true and make sure the proxy overwrites
X-Forwarded-For rather than appending to it. Trusting that header with
nothing in front of the server hands every caller their own rate limit for
the price of a header line, which is the same as having none.
Fields§
§enabled: boolTurn every limit off — the app’s, the resources’ and the functions’ — without deleting what they say. The switch to flip while an incident is being diagnosed.
default: RateLimitRuleThe rule every endpoint gets unless something narrower says otherwise.
"off" (the default) limits nothing.
trust_proxy_headers: boolRead the client address from X-Forwarded-For / X-Real-IP when
present, instead of the peer socket. Only true behind a proxy you
control; see the section note above.
cleanup_interval_secs: u64How often the tracked clients are swept for buckets nobody has used.
stale_after_secs: u64How long a client’s bucket is kept after their last request. Bounds what a flood of one-request-each addresses can cost in memory.
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more