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:
parent
c5d50737f0
commit
1d0f1ed446
2 changed files with 11 additions and 1 deletions
|
@ -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}`,
|
||||
|
|
|
@ -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
|
||||
> {
|
||||
|
|
Loading…
Add table
Reference in a new issue