mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(node/http): don't send destroyed requests (#24498)
Make sure that already destroyed requests are not actually sent. This error was discovered in jsdom's test suite.
This commit is contained in:
parent
2a86edf0af
commit
9a0d59d95d
2 changed files with 23 additions and 0 deletions
|
@ -765,6 +765,9 @@ class ClientRequest extends OutgoingMessage {
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
end(chunk?: any, encoding?: any, cb?: any): this {
|
end(chunk?: any, encoding?: any, cb?: any): this {
|
||||||
|
// Do nothing if request is already destroyed.
|
||||||
|
if (this.destroyed) return this;
|
||||||
|
|
||||||
if (typeof chunk === "function") {
|
if (typeof chunk === "function") {
|
||||||
cb = chunk;
|
cb = chunk;
|
||||||
chunk = null;
|
chunk = null;
|
||||||
|
@ -797,6 +800,8 @@ class ClientRequest extends OutgoingMessage {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
abort() {
|
||||||
|
|
|
@ -1003,6 +1003,24 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"[node/http] destroyed requests should not be sent",
|
||||||
|
async () => {
|
||||||
|
let receivedRequest = false;
|
||||||
|
const server = Deno.serve(() => {
|
||||||
|
receivedRequest = true;
|
||||||
|
return new Response(null);
|
||||||
|
});
|
||||||
|
const request = http.request(`http://localhost:${server.addr.port}/`);
|
||||||
|
request.destroy();
|
||||||
|
request.end("hello");
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 500));
|
||||||
|
assertEquals(receivedRequest, false);
|
||||||
|
await server.shutdown();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Deno.test("[node/http] node:http exports globalAgent", async () => {
|
Deno.test("[node/http] node:http exports globalAgent", async () => {
|
||||||
const http = await import("node:http");
|
const http = await import("node:http");
|
||||||
assert(
|
assert(
|
||||||
|
|
Loading…
Reference in a new issue