mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
fix: Allow ArrayBuffer as Fetch request body (#5831)
This commit is contained in:
parent
c9f0e34e29
commit
1c4a9665e2
2 changed files with 15 additions and 0 deletions
|
@ -505,6 +505,8 @@ export async function fetch(
|
|||
contentType = "text/plain;charset=UTF-8";
|
||||
} else if (isTypedArray(init.body)) {
|
||||
body = init.body;
|
||||
} else if (init.body instanceof ArrayBuffer) {
|
||||
body = new Uint8Array(init.body);
|
||||
} else if (init.body instanceof URLSearchParams) {
|
||||
body = new TextEncoder().encode(init.body.toString());
|
||||
contentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
|
|
|
@ -258,6 +258,19 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function fetchInitArrayBufferBody(): Promise<void> {
|
||||
const data = "Hello World";
|
||||
const response = await fetch("http://localhost:4545/echo_server", {
|
||||
method: "POST",
|
||||
body: new TextEncoder().encode(data).buffer,
|
||||
});
|
||||
const text = await response.text();
|
||||
assertEquals(text, data);
|
||||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function fetchInitURLSearchParamsBody(): Promise<void> {
|
||||
|
|
Loading…
Reference in a new issue