mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
fix(node/http): use fake socket and proper url handling (#19340)
Fixes https://github.com/denoland/deno/issues/19349 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
c76f9a0227
commit
5aca8b9e5d
3 changed files with 49 additions and 41 deletions
|
@ -195,11 +195,14 @@ Deno.test("[node/http] request default protocol", async () => {
|
|||
// @ts-ignore IncomingMessageForClient
|
||||
// deno-lint-ignore no-explicit-any
|
||||
let clientRes: any;
|
||||
// deno-lint-ignore no-explicit-any
|
||||
let clientReq: any;
|
||||
server.listen(() => {
|
||||
const req = http.request(
|
||||
clientReq = http.request(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
{ host: "localhost", port: (server.address() as any).port },
|
||||
(res) => {
|
||||
assert(res.socket instanceof EventEmitter);
|
||||
assertEquals(res.complete, false);
|
||||
res.on("data", () => {});
|
||||
res.on("end", () => {
|
||||
|
@ -210,13 +213,14 @@ Deno.test("[node/http] request default protocol", async () => {
|
|||
promise2.resolve();
|
||||
},
|
||||
);
|
||||
req.end();
|
||||
clientReq.end();
|
||||
});
|
||||
server.on("close", () => {
|
||||
promise.resolve();
|
||||
});
|
||||
await promise;
|
||||
await promise2;
|
||||
assert(clientReq.socket instanceof EventEmitter);
|
||||
assertEquals(clientRes!.complete, true);
|
||||
});
|
||||
|
||||
|
@ -596,3 +600,24 @@ Deno.test("[node/http] ClientRequest PUT", async () => {
|
|||
await def;
|
||||
assertEquals(body, "hello world");
|
||||
});
|
||||
|
||||
Deno.test("[node/http] ClientRequest search params", async () => {
|
||||
let body = "";
|
||||
const def = deferred();
|
||||
const req = http.request({
|
||||
host: "localhost:4545",
|
||||
path: "search_params?foo=bar",
|
||||
}, (resp) => {
|
||||
resp.on("data", (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
resp.on("end", () => {
|
||||
def.resolve();
|
||||
});
|
||||
});
|
||||
req.once("error", (e) => def.reject(e));
|
||||
req.end();
|
||||
await def;
|
||||
assertEquals(body, "foo=bar");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue