diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-09-08 17:46:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-08 11:46:15 +0200 |
commit | 1d0f1ed446acd2db7c052503570c9249e7b841e9 (patch) | |
tree | 96fd01ce451b48dc945df8d8237d4e30841c97d8 /cli | |
parent | c5d50737f05f6b1999d1973ba5bd260473aadcbd (diff) |
fix: Empty Response body returns 0-byte array (#7387)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/rt/24_body.js | 2 | ||||
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/cli/rt/24_body.js b/cli/rt/24_body.js index a3348907b..f755e2bad 100644 --- a/cli/rt/24_body.js +++ b/cli/rt/24_body.js @@ -85,7 +85,7 @@ const enc = new TextEncoder(); return enc.encode(bodySource.toString()).buffer; } else if (!bodySource) { - return null; + return new ArrayBuffer(0); } throw new Error( `Body type not implemented: ${bodySource.constructor.name}`, diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 012ce7b34..4bdb54d9e 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -738,6 +738,16 @@ unitTest(function responseRedirect(): void { assertEquals(redir.type, "default"); }); +unitTest(async function responseWithoutBody(): Promise<void> { + const response = new Response(); + assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); + assertEquals(await response.blob(), new Blob([])); + assertEquals(await response.text(), ""); + await assertThrowsAsync(async () => { + await response.json(); + }); +}); + unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise< void > { |