Skip to content

Commit

Permalink
fix(ext/node): add ClientRequest#setNoDelay (#21694)
Browse files Browse the repository at this point in the history
Fixes #18316
  • Loading branch information
littledivy authored and bartlomieju committed Jan 4, 2024
1 parent 375164c commit 1149ec8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cli/tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>();
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<void>();
Expand Down
5 changes: 5 additions & 0 deletions ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1149ec8

Please sign in to comment.