Skip to content

fix(proxy): forward user-agent, pass back Allow, validate /codes, and drop rate headers on uncounted calls - #41

Merged
jm-rivera merged 5 commits into
devfrom
fix/proxy-diagnostics
Oct 23, 2026
Merged

jm-rivera merged 5 commits into
devfrom
fix/proxy-diagnostics

Conversation

@jm-rivera

@jm-rivera jm-rivera commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

The proxy forwards the caller's User-Agent to the APIs, so their request logs name the client library (dfo-python/<version>), and passes Allow back, so a 405 names the methods the route takes (src/lib/proxy/headers.ts). GET /codes/{code} now checks the code before forwarding: codeTarget in src/lib/proxy/codes.ts accepts only the registry's snake_case shape, and src/app/codes/[code]/route.ts answers 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. hit in src/lib/proxy/rateLimit.ts fails open on a database error or timeout, and headers on that call would describe a count that never ran, so its verdict says counted: false. rateHeaders moves to src/lib/proxy/rateHeaders.ts, a module free of server-only that node --test can load, and forward.ts and src/lib/search/storedFile.ts import it from there.

Testing: pnpm typecheck, pnpm lint and pnpm lint:css pass, and node --test over every suite in pnpm test except db/test passed 1,657 tests. The db/test suite needs a Postgres and did not run.

… 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.
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.
@jm-rivera jm-rivera changed the title fix(proxy): forward user-agent, pass back x-dfo-commit and Allow, and serve /codes fix(proxy): forward user-agent, pass back Allow, validate /codes, and drop rate headers on uncounted calls Oct 23, 2026
@jm-rivera
jm-rivera merged commit f56a812 into dev Oct 23, 2026
1 check passed
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