From 00f6ef2747feefdcc6ed76842cd9d03c37225ed0 Mon Sep 17 00:00:00 2001 From: Kunal Kundu Date: Sat, 31 Dec 2022 21:31:46 +0530 Subject: [PATCH] fix: send response body with status text for invalid methods --- src/commands/dev/dev.mjs | 2 +- tests/integration/500.command.dev.test.cjs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/dev/dev.mjs b/src/commands/dev/dev.mjs index 8e846b2003c..7fecaa2b133 100644 --- a/src/commands/dev/dev.mjs +++ b/src/commands/dev/dev.mjs @@ -71,7 +71,7 @@ const startStaticServer = async ({ settings }) => { server.addHook('onRequest', (req, reply, done) => { const validMethods = ['GET', 'HEAD'] if (!validMethods.includes(req.method)) { - reply.code(405).send() + reply.code(405).send('Method Not Allowed') } done() }) diff --git a/tests/integration/500.command.dev.test.cjs b/tests/integration/500.command.dev.test.cjs index 66ece3d6ebb..d7210173b1e 100644 --- a/tests/integration/500.command.dev.test.cjs +++ b/tests/integration/500.command.dev.test.cjs @@ -166,7 +166,7 @@ test('should handle form submission with a background function', async (t) => { }) }) -test('should not handle form submission when content type is `text/plain`', async (t) => { +test.only('should not handle form submission when content type is `text/plain`', async (t) => { await withSiteBuilder('site-with-form-text-plain', async (builder) => { builder .withContentFile({ @@ -197,6 +197,7 @@ test('should not handle form submission when content type is `text/plain`', asyn }, }) .catch((error) => error.response) + t.is(response.statusCode, 405) t.is(response.body, 'Method Not Allowed') }) })