Repository navigation
feat(edge): send RateLimit headers on route-rule 429s - #1813
Open
SibilSoren wants to merge 1 commit into
Open
SibilSoren wants to merge 1 commit into
SibilSoren wants to merge 1 commit into
Conversation
5 tasks done
When a route rule's rate limit trips, the guard now sends RateLimit-Policy and RateLimit (draft-ietf-httpapi-ratelimit-headers) along with Retry-After. The quota is the compiled limit (rps + burst) over the fixed 1s window, so a client can see which limit it hit and that it resets within a second. Requests the limit lets through are unchanged. Closes oblien#1227
SibilSoren
force-pushed
the
feat/edge-ratelimit-headers
branch
from
November 18, 2026 04:54
81efe43 to
ea7fd3a
Compare
This was referenced Nov 19, 2026
Contributor
Author
|
@Hydralerne, could you take a look at this when you get a chance? Nothing on main has touched these files since I opened it, so it still merges cleanly and CI passes. I'm holding off on #1225 until this lands, since it changes the same 429 path. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a route rule's rate limit trips, the edge now sends
RateLimit-PolicyandRateLimitalong withRetry-After, so the client can see which limit it hit and when it resets.Motivation
#1227 asks for the IETF RateLimit fields on rule-limited responses. Right now a 429 from a rule carries only
Retry-After: 1and nginx's default body, so a client has no way to know what the limit is.I described this approach on the issue on 8 Nov. One of the two questions I asked there has since been settled on main: since #1739 the guard writes rule-defined response headers, and the contract test no longer pins
Retry-Afteras the only header it sets.Related issue
Closes #1227
Changes
packages/adapters
rules_guard.lua: on the rate-limit 429 path, setRateLimit-Policy: "rule";q=<limit>;w=1andRateLimit: "rule";r=0;t=1beforeRetry-After.qis the compiledrl.limit(rps + burst), already an integer aftercompile_spec, and it's written with%d. Everything else is a literal. Nothing changes outside the 429 path.lua-embedded.tsregenerated withbun run embed:lua.apps/api
routing-rules.e2e.test.ts: the existing real-OpenResty rate-limit test now also checks both fields on every 429, and checks that the requests the limit lets through don't get them.apps/web
guides/the-edge.mdx: a short paragraph under the rule examples, with the 429 that the/loginexample rule sends.Verification
The api failures are the same 4 timezone-dependent tests in
domain-diagnostics.test.tsas in #1743, #1808 and #1809. They fail on main in IST and pass withTZ=UTC. Every other workspace passed, including@repo/adapters(6172 passed, 7 skipped) and@repo/web.A 429 and a 200 from that test (openresty/1.27.1.1,
rps: 1, burst: 1), printed with a temporary log line I didn't keep:A few choices worth checking:
tandRetry-Afterstay at 1 because the window is fixed at one second. If longer windows come in ([Feature]: Longer windows for route-rule rate limits #1225),w,tandRetry-Aftershould come from the rule's window instead."rule", so no rule value except the integer limit ends up in a header.Checklist
bun run test,bun run --cwd <workspace> lint, andbun formatall pass locally (all pass except the timezone-dependent api tests above;routing-rules.e2e.test.tsalready has Prettier drift on main, so I checked that Prettier has nothing to change on the lines I touched)