refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)

This commit re-implements `ext/fetch` and all dependent crates
using `hyper` and `hyper-util`, instead of `reqwest`.

The reasoning is that we want to have greater control and access
to low level `hyper` APIs when implementing `fetch` API as well
as `node:http` module.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Sean McArthur 2024-07-12 15:51:37 -07:00 committed by GitHub
parent 2fca4f11fe
commit f6fd6619e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1530 additions and 345 deletions

View file

@ -67,7 +67,7 @@ Deno.test(
await fetch(`http://localhost:${port}`);
},
TypeError,
"error sending request for url",
"client error (Connect)",
);
},
);
@ -80,7 +80,7 @@ Deno.test(
await fetch("http://nil/");
},
TypeError,
"error sending request for url",
"client error (Connect)",
);
},
);
@ -688,7 +688,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@ -720,7 +720,7 @@ Deno.test(
"accept: text/html\r\n",
"accept-language: en-US\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@ -750,15 +750,16 @@ Deno.test(
const actual = new TextDecoder().decode((await bufPromise).bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
`content-length: ${body.length}\r\n`,
"hello: World\r\n",
"foo: Bar\r\n",
"content-type: text/plain;charset=UTF-8\r\n",
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
`content-length: ${body.length}\r\n\r\n`,
`\r\n`,
body,
].join("");
assertEquals(actual, expected);
@ -789,14 +790,15 @@ Deno.test(
const actual = new TextDecoder().decode((await bufPromise).bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
`content-length: ${body.byteLength}\r\n`,
"hello: World\r\n",
"foo: Bar\r\n",
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
`content-length: ${body.byteLength}\r\n\r\n`,
`\r\n`,
bodyStr,
].join("");
assertEquals(actual, expected);
@ -827,7 +829,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n\r\n`,
].join("");
assertEquals(actual, expected);
@ -859,7 +861,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n\r\n",
"accept-encoding: gzip,br\r\n\r\n",
].join("");
assertEquals(actual, expected);
},
@ -1226,7 +1228,7 @@ Deno.test(
"accept: */*\r\n",
"accept-language: *\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
"accept-encoding: gzip,br\r\n",
`host: ${addr}\r\n`,
`transfer-encoding: chunked\r\n\r\n`,
"B\r\n",
@ -1824,7 +1826,7 @@ Deno.test(
await fetch(`http://${addr}/`);
},
TypeError,
"error sending request",
"client error",
);
listener.close();
@ -1880,7 +1882,7 @@ Deno.test(
await response.arrayBuffer();
},
Error,
"error decoding response body",
"body",
);
listener.close();