Skip to content

Add per-route rate-limit overrides on map-form routes - #193

Open
williamthome wants to merge 2 commits into
feat/real-ip-resolutionfrom
feat/per-route-limits
Open

Add per-route rate-limit overrides on map-form routes#193
williamthome wants to merge 2 commits into
feat/real-ip-resolutionfrom
feat/per-route-limits

Conversation

@williamthome

Copy link
Copy Markdown
Member

Description

The rate_limit guard is listener-global, so a cheap health check and an expensive report endpoint share one budget. A rate_limit key on a map-form route now overrides the listener default for that path, with its own bucket namespace so the two do not contend. Routes that declare no override keep using the listener-global limit, and when no route declares one the compiled subset is undefined and the lookup is skipped entirely. Matching reuses the same path and method matchers as dispatch, first-match-wins in declaration order; a path match whose method falls outside the route's allowlist keeps scanning, so an override only applies to the methods that route declares.

Routes = [
    #{path => ~"/health", handler => health_h},
    #{path => ~"/reports", handler => reports_h, methods => [~"POST"],
      rate_limit => #{limit => 5, window => 60_000}}
].

Per-route configs are validated and derived to their {Rate, Cap, Cost} triple at listener init, so a bad config raises there rather than on the request path.

@williamthome
williamthome force-pushed the feat/per-route-limits branch from 5703256 to 7eb517d Compare August 2, 2026 14:58
@williamthome
williamthome force-pushed the feat/per-route-limits branch from 7eb517d to 3d71f6b Compare August 3, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant