mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix(fetch): set content-length for empty POST/PUT (#12703)
This commit changes `fetch` to set `content-length: 0` on POST and PUT requests with no body.
This commit is contained in:
parent
75793baae8
commit
0de6d1edc4
3 changed files with 68 additions and 1 deletions
|
@ -640,6 +640,7 @@ unitTest(
|
|||
const actual = new TextDecoder().decode((await bufPromise).bytes());
|
||||
const expected = [
|
||||
"POST /blah HTTP/1.1\r\n",
|
||||
"content-length: 0\r\n",
|
||||
"hello: World\r\n",
|
||||
"foo: Bar\r\n",
|
||||
"accept: */*\r\n",
|
||||
|
@ -1416,3 +1417,60 @@ unitTest(
|
|||
assertEquals(await res.text(), fixture);
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function fetchContentLengthPost() {
|
||||
const response = await fetch("http://localhost:4545/content_length", {
|
||||
method: "POST",
|
||||
});
|
||||
const length = await response.text();
|
||||
assertEquals(length, 'Some("0")');
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function fetchContentLengthPut() {
|
||||
const response = await fetch("http://localhost:4545/content_length", {
|
||||
method: "PUT",
|
||||
});
|
||||
const length = await response.text();
|
||||
assertEquals(length, 'Some("0")');
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function fetchContentLengthPatch() {
|
||||
const response = await fetch("http://localhost:4545/content_length", {
|
||||
method: "PATCH",
|
||||
});
|
||||
const length = await response.text();
|
||||
assertEquals(length, "None");
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function fetchContentLengthPostWithStringBody() {
|
||||
const response = await fetch("http://localhost:4545/content_length", {
|
||||
method: "POST",
|
||||
body: "Hey!",
|
||||
});
|
||||
const length = await response.text();
|
||||
assertEquals(length, 'Some("4")');
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ permissions: { net: true } },
|
||||
async function fetchContentLengthPostWithBufferBody() {
|
||||
const response = await fetch("http://localhost:4545/content_length", {
|
||||
method: "POST",
|
||||
body: new TextEncoder().encode("Hey!"),
|
||||
});
|
||||
const length = await response.text();
|
||||
assertEquals(length, 'Some("4")');
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue