Skip to main content

Module general

Module general 

Source
Expand description

General-purpose middlewares for the router.

Currently provides rate_limiter, a per-caller request-cap hook. Attach the returned Middleware to a route or pass it as a global middleware so over-limit requests fail with a 429 before the handler runs.

let mw = rate_limiter(limiter, 100);
self.mount_get(&mut router, "/list", desc, handler, vec![mw]);

Functions§

rate_limiter
Builds middleware enforcing limit requests per minute per caller. The caller key is the context’s user id, or the x-forwarded-for header value falling back to "anonymous". Over-limit requests fail with a 429 ErrorResult.