1 Commits
Author SHA1 Message Date
chrnx 03def0324b 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>
2026-10-24 22:22:04 -05:00
4 changed files with 1 additions and 17 deletions

No files matched your search

-5
View File
@@ -327,11 +327,6 @@ npm treats versions as semver and semver forbids leading zeros.
handing the handler partial data. The Node server and `app.fetch` parse multipart through the handing the handler partial data. The Node server and `app.fetch` parse multipart through the
same path, so the fix applies to both. same path, so the fix applies to both.
- **`maxParts: N` accepts exactly N parts** (#118). busboy signals its parts limit once the count
reaches it, so a body of exactly `maxParts` parts was rejected with `400 Invalid multipart body`
and only N−1 got through. busboy now gets one part of headroom, the same way `fieldSize` does:
N parts are accepted and N+1 are rejected, as the option's name says. Both the route-level and
the server-level `maxParts` were affected, on the Node server and `app.fetch` alike.
- **`@header('Content-Type')` finds the header** (GitHub #37). Every adapter stores request - **`@header('Content-Type')` finds the header** (GitHub #37). Every adapter stores request
header names lower-cased, and `@header`/`@headers` looked the name up as written, so any name header names lower-cased, and `@header`/`@headers` looked the name up as written, so any name
with a capital letter reached the handler as `undefined`. The name is now matched without case. with a capital letter reached the handler as `undefined`. The name is now matched without case.
+1 -4
View File
@@ -99,14 +99,11 @@ export function parseMultipart(raw: Buffer, boundary: string, opts: MultipartOpt
// busboy flags a field as truncated once it *reaches* `fieldSize`, so a field of exactly // busboy flags a field as truncated once it *reaches* `fieldSize`, so a field of exactly
// `maxFieldBytes` needs one byte of headroom to count as whole. // `maxFieldBytes` needs one byte of headroom to count as whole.
const fieldSize = opts.maxFieldBytes === undefined ? undefined : opts.maxFieldBytes + 1; const fieldSize = opts.maxFieldBytes === undefined ? undefined : opts.maxFieldBytes + 1;
// Same for parts: busboy emits `partsLimit` once the count *reaches* `parts`, so a body of
// exactly `maxParts` parts needs one of headroom to be accepted (Gitea #118).
const parts = opts.maxParts + 1;
try { try {
bb = busboy({ bb = busboy({
headers: { 'content-type': `multipart/form-data; boundary=${boundary}` }, headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
limits: { parts, fieldSize }, limits: { parts: opts.maxParts, fieldSize },
}); });
} catch { } catch {
return fail(); return fail();
-2
View File
@@ -147,7 +147,6 @@ describe('multipart limits on app.fetch (#105)', () => {
@Module({ mountpoint: '/', controllers: [C] }) class CMod {} @Module({ mountpoint: '/', controllers: [C] }) class CMod {}
app = createApp({ modules: [CMod] }); app = createApp({ modules: [CMod] });
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200); // #118
const r = await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) })); const r = await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }));
expect(r.status).toBe(400); expect(r.status).toBe(400);
@@ -176,7 +175,6 @@ describe('multipart limits on app.fetch (#105)', () => {
app = createApp({ modules: [CMod], limits: { maxParts: 2 } }); app = createApp({ modules: [CMod], limits: { maxParts: 2 } });
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(1) }))).status).toBe(200); expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(1) }))).status).toBe(200);
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200);
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }))).status).toBe(400); expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }))).status).toBe(400);
}); });
}); });
-6
View File
@@ -79,12 +79,6 @@ describe('parseMultipart', () => {
await expect(parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).rejects.toThrow(); await expect(parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).rejects.toThrow();
}); });
// Gitea #118: busboy signals the limit when the count reaches it, which used to reject exactly N.
it('exactly maxParts parts → accepted', async () => {
const b = body([field('a', '1'), field('b', '2')]);
expect((await parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).fields).toEqual({ a: '1', b: '2' });
});
// GitHub #39: busboy cuts a field at its size limit and only flags it, so the parser has to refuse // GitHub #39: busboy cuts a field at its size limit and only flags it, so the parser has to refuse
// the body rather than hand the handler partial data. // the body rather than hand the handler partial data.
it('a field over maxFieldBytes → rejects with 413 instead of truncating', async () => { it('a field over maxFieldBytes → rejects with 413 instead of truncating', async () => {