mirror of
https://github.com/denoland/deno.git
synced 2025-09-30 14:11:14 +00: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";
|
contentType = "text/plain;charset=UTF-8";
|
||||||
} else if (isTypedArray(init.body)) {
|
} else if (isTypedArray(init.body)) {
|
||||||
body = init.body;
|
body = init.body;
|
||||||
|
} else if (init.body instanceof ArrayBuffer) {
|
||||||
|
body = new Uint8Array(init.body);
|
||||||
} else if (init.body instanceof URLSearchParams) {
|
} else if (init.body instanceof URLSearchParams) {
|
||||||
body = new TextEncoder().encode(init.body.toString());
|
body = new TextEncoder().encode(init.body.toString());
|
||||||
contentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
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(
|
unitTest(
|
||||||
{ perms: { net: true } },
|
{ perms: { net: true } },
|
||||||
async function fetchInitURLSearchParamsBody(): Promise<void> {
|
async function fetchInitURLSearchParamsBody(): Promise<void> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue