1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix: Empty Response body returns 0-byte array (#7387)

This commit is contained in:
Casper Beyer 2020-09-08 17:46:15 +08:00 committed by GitHub
parent c5d50737f0
commit 1d0f1ed446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -85,7 +85,7 @@
const enc = new TextEncoder(); const enc = new TextEncoder();
return enc.encode(bodySource.toString()).buffer; return enc.encode(bodySource.toString()).buffer;
} else if (!bodySource) { } else if (!bodySource) {
return null; return new ArrayBuffer(0);
} }
throw new Error( throw new Error(
`Body type not implemented: ${bodySource.constructor.name}`, `Body type not implemented: ${bodySource.constructor.name}`,

View file

@ -738,6 +738,16 @@ unitTest(function responseRedirect(): void {
assertEquals(redir.type, "default"); 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< unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
void void
> { > {