Skip to content

Commit bef54f6

Browse files
authored
fix: allow methods check (#8968)
fixes #8967
1 parent 15c2777 commit bef54f6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.changeset/dirty-days-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: correctly include exported http methods in allow header

packages/kit/src/runtime/server/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function method_not_allowed(mod, method) {
4141
export function allowed_methods(mod) {
4242
const allowed = [];
4343

44-
for (const method in ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']) {
44+
for (const method of ['GET', 'POST', 'PUT', 'PATCH', 'DELETE']) {
4545
if (method in mod) allowed.push(method);
4646
}
4747

packages/kit/test/apps/basics/test/server.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ test.describe('Endpoints', () => {
108108
});
109109
});
110110

111+
test('invalid request method returns allow header', async ({ request }) => {
112+
const response = await request.post('/endpoint-output/body');
113+
114+
expect(response.status()).toBe(405);
115+
expect(response.headers()['allow'].includes('GET'));
116+
});
117+
111118
// TODO all the remaining tests in this section are really only testing
112119
// setResponse, since we're not otherwise changing anything on the response.
113120
// might be worth making these unit tests instead

0 commit comments

Comments
 (0)