fix(params): match @header names without case (GitHub #37)
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:
4 files changed
+58
-2
No files matched your search
@@ -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) {}
|
||||
|
||||
Reference in new issue
Block a user