Repository navigation
fix(proxy): forward user-agent, pass back Allow, validate /codes, and drop rate headers on uncounted calls - #41
Merged
Merged
Conversation
… serve /codes
The proxy forwards the caller's user-agent to the APIs, so their logs name the client library, and passes back x-dfo-commit and Allow beside Server-Timing and x-dfo-trace-id. GET /codes/{code} forwards to the API's refusal-code registry, so the root-relative `type` link in a problem document resolves on the public host.
A call the limiter could not count (a database error or timeout, which fails open) carries no X-RateLimit-* headers, since they would describe a count that never ran. `rateHeaders` moves to rateHeaders.ts, a module free of server-only, so node --test loads it.
`encodeURIComponent` leaves `.` alone, so `/codes/..` forwarded to `${SEARCH_API_BASE}/codes/..`, which fetch resolves to the API root, carrying the site's ID token and the caller's query. `codeTarget` now answers an address only for a snake_case code, the shape of every code in the registry, and the route answers 404 for anything else. The rate-limit comments name /codes among the limited routes, and `downloadAllowance` says its headers go out only on a counted call.
… the api allowance The proxy comments say a call carries the caller's user-agent, that a /codes call the route forwards counts against the `api` allowance, and that a value no code can be is refused before any count. That 404 carries `retry` and `detail`, as the Studio proxy's does.
jm-rivera
marked this pull request as ready for review
October 22, 2026 13:32
Keep dev's x-dfo-* prefix passthrough and its /openapi.json route, and
drop this branch's explicit x-dfo-commit and x-dfo-trace-id entries. The
/codes/{code} route keeps this branch's `codeTarget` check and query
forwarding with dev's unreachable message.
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.
The proxy forwards the caller's
User-Agentto the APIs, so their request logs name the client library (dfo-python/<version>), and passesAllowback, so a 405 names the methods the route takes (src/lib/proxy/headers.ts).GET /codes/{code}now checks the code before forwarding:codeTargetinsrc/lib/proxy/codes.tsaccepts only the registry's snake_case shape, andsrc/app/codes/[code]/route.tsanswers any other value with a 404 in the Studio proxy's{error, retry, detail}form, so/codes/..cannot reach the API root. The query string goes upstream with the code.A call the limiter could not count carries no
X-RateLimit-*headers.hitinsrc/lib/proxy/rateLimit.tsfails open on a database error or timeout, and headers on that call would describe a count that never ran, so its verdict sayscounted: false.rateHeadersmoves tosrc/lib/proxy/rateHeaders.ts, a module free ofserver-onlythatnode --testcan load, andforward.tsandsrc/lib/search/storedFile.tsimport it from there.Testing:
pnpm typecheck,pnpm lintandpnpm lint:csspass, andnode --testover every suite inpnpm testexceptdb/testpassed 1,657 tests. Thedb/testsuite needs a Postgres and did not run.