fix(params): match @header names without case (GitHub #37)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 37s

Node's IncomingHttpHeaders and the fetch adapter's headersToRecord
both store request header names lower-cased, but resolveOne looked a
@header/@headers key up exactly as the decorator wrote it. Any name
with a capital letter, such as @header('Content-Type'), therefore
reached the handler as undefined.

resolveOne now lower-cases the key for the headers source before the
lookup. A picked bag (@headers([...])) keeps the names as written, so a
handler reads back the key it asked for; @headers() with no argument
still returns the whole lower-cased bag.

test/params.test.ts covers the single and picked forms on resolveArgs;
test/header-case.test.ts sends a request over app.fetch and the Node
server. All three fail without the fix.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-24 22:22:04 -05:00
1 parent 87b6e7a4b0
commit 03def0324b
4 files changed
+58 -2

No files matched your search

+10
View File
@@ -110,6 +110,16 @@ describe('@headers / @header', () => {
expect(args[1]).toEqual({ authorization: 'Bearer t0ken', 'x-trace': 'abc' });
});
// GitHub #37: adapters store header names lower-cased; the decorator name is matched without case.
it('@header and @headers([...]) match the name without case, keeping the written names', async () => {
class Ctl {
handle(@header('Authorization') _auth: string, @headers(['X-Trace', 'x-count']) _some: unknown) {}
}
const args = await resolveArgs(getArgs(Ctl, 'handle'), { headers: reqHeaders });
expect(args[0]).toBe('Bearer t0ken');
expect(args[1]).toEqual({ 'X-Trace': 'abc', 'x-count': '5' });
});
it('@header(name, schema) validates the picked header', async () => {
class Ctl {
handle(@header('x-count', numFromStr) _count: number) {}