Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-avocados-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: correct allow header methods list for 405s
10 changes: 4 additions & 6 deletions packages/kit/src/runtime/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ export function method_not_allowed(mod, method) {

/** @param {Partial<Record<import('types').HttpMethod, any>>} mod */
export function allowed_methods(mod) {
const allowed = [];
const allowed = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'].filter(
(method) => method in mod
);

for (const method in ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) {
if (method in mod) allowed.push(method);
}

if (mod.GET || mod.HEAD) allowed.push('HEAD');
if ('GET' in mod || 'HEAD' in mod) allowed.push('HEAD');

return allowed;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/kit/test/apps/basics/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ test.describe('Endpoints', () => {
const response = await request.post('/endpoint-output/body');

expect(response.status()).toBe(405);
expect(response.headers()['allow'].includes('GET'));

const allow_header = response.headers()['allow'];
expect(allow_header).toMatch(/\bGET\b/);
expect(allow_header).toMatch(/\bHEAD\b/);
});

// TODO all the remaining tests in this section are really only testing
Expand Down