summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/polyfills/http.ts5
-rw-r--r--tests/unit_node/http_test.ts18
2 files changed, 23 insertions, 0 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 0ef245902..51d228d4e 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -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() {
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts
index 71043d985..9a37722c7 100644
--- a/tests/unit_node/http_test.ts
+++ b/tests/unit_node/http_test.ts
@@ -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(