From a6c840d15020b72326832c19e6a5ac0d95b9bdca Mon Sep 17 00:00:00 2001 From: Craig Morten Date: Mon, 5 Jul 2021 11:38:12 +0100 Subject: [PATCH] fix(fetch): OPTIONS should be allowed a non-null body (#11242) --- cli/tests/unit/fetch_test.ts | 10 ++++++++++ extensions/fetch/26_fetch.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 46eceb50c8..a84e183678 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1217,3 +1217,13 @@ unitTest( await done; }, ); + +unitTest( + { perms: { net: true } }, + async function fetchHeadRespBody() { + const res = await fetch("http://localhost:4545/echo_server", { + method: "HEAD", + }); + assertEquals(res.body, null); + }, +); diff --git a/extensions/fetch/26_fetch.js b/extensions/fetch/26_fetch.js index 438866fb33..47b07be0ba 100644 --- a/extensions/fetch/26_fetch.js +++ b/extensions/fetch/26_fetch.js @@ -271,7 +271,7 @@ if (nullBodyStatus(response.status)) { core.close(resp.responseRid); } else { - if (req.method === "HEAD" || req.method === "OPTIONS") { + if (req.method === "HEAD" || req.method === "CONNECT") { response.body = null; core.close(resp.responseRid); } else {