1
0
Fork 0
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:
Marvin Hagemeister 2024-07-10 12:01:08 +02:00 committed by GitHub
parent 2a86edf0af
commit 9a0d59d95d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View file

@ -765,6 +765,9 @@ class ClientRequest extends OutgoingMessage {
// deno-lint-ignore no-explicit-any
end(chunk?: any, encoding?: any, cb?: any): this {
// Do nothing if request is already destroyed.
if (this.destroyed) return this;
if (typeof chunk === "function") {
cb = chunk;
chunk = null;
@ -797,6 +800,8 @@ class ClientRequest extends OutgoingMessage {
//
}
})();
return this;
}
abort() {

View file

@ -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 () => {
const http = await import("node:http");
assert(