diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index 5285d8e23e..72525d803f 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -584,6 +584,27 @@ Deno.test("[node/http] ClientRequest setTimeout", async () => { assertEquals(body, "HTTP/1.1"); }); +Deno.test("[node/http] ClientRequest setNoDelay", async () => { + let body = ""; + const { promise, resolve, reject } = Promise.withResolvers(); + const timer = setTimeout(() => reject("timed out"), 50000); + const req = http.request("http://localhost:4545/http_version", (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + resolve(); + }); + }); + req.setNoDelay(true); + req.once("error", (e) => reject(e)); + req.end(); + await promise; + clearTimeout(timer); + assertEquals(body, "HTTP/1.1"); +}); + Deno.test("[node/http] ClientRequest PATCH", async () => { let body = ""; const { promise, resolve, reject } = Promise.withResolvers(); diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index d458541628..e49f717023 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -892,6 +892,11 @@ class ClientRequest extends OutgoingMessage { } headers.push([key, value]); } + + // Once a socket is assigned to this request and is connected socket.setNoDelay() will be called. + setNoDelay() { + this.socket?.setNoDelay?.(); + } } // isCookieField performs a case-insensitive comparison of a provided string