Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): add ClientRequest#setNoDelay #21694

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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