Skip to content

Commit

Permalink
Capture all IANA top level content types
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-G committed Jan 24, 2025
1 parent 2acfb3b commit 4f7c4b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/validate-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const VALID_CACHE_CONTROL_DIRECTIVES = new Set([
]);

const CONTENT_TYPE_PATTERN =
/^(application|audio|font|image|model|text|video|x-[a-z]+)\/[-+.\w]+$/i;
/^(application|audio|example|font|haptics|image|message|model|multipart|text|video|x-[a-z]+)\/[-+.\w]+$/i;

/** @type {Record<string, (value: string) => void>} */
const HEADER_VALIDATORS = {
Expand Down
19 changes: 19 additions & 0 deletions packages/kit/src/runtime/server/validate-headers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ describe('validateHeaders', () => {
expect.stringContaining('cache-control header contains empty directives')
);
});

test('accepts multiple cache-control values', () => {
validateHeaders({ 'cache-control': 'max-age=3600, s-maxage=7200' });
expect(console.warn).not.toHaveBeenCalled();
});
});

describe('content-type header', () => {
Expand Down Expand Up @@ -89,10 +94,24 @@ describe('validateHeaders', () => {
expect.stringContaining('Invalid content-type value "bad/type"')
);
});

test('handles case-insensitive content-types', () => {
validateHeaders({ 'content-type': 'TEXT/HTML; charset=utf-8' });
expect(console.warn).not.toHaveBeenCalled();
});
});

test('allows unknown headers', () => {
validateHeaders({ 'x-custom-header': 'some-value' });
expect(console.warn).not.toHaveBeenCalled();
});

test('handles multiple headers simultaneously', () => {
validateHeaders({
'cache-control': 'max-age=3600',
'content-type': 'text/html',
'x-custom': 'value'
});
expect(console.warn).not.toHaveBeenCalled();
});
});

0 comments on commit 4f7c4b9

Please sign in to comment.