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

http: Add noDelay to http.request() options. #31539

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,9 @@ changes:
**Default:** 8192 (8KB).
* `method` {string} A string specifying the HTTP request method. **Default:**
`'GET'`.
* `noDelay` {boolean} A boolean with which to call [`socket.setNoDelay()`][]
when a socket connection is established. This only applies when the
underlying connection is a TCP socket.
* `path` {string} Request path. Should include query string if any.
E.G. `'/index.html?page=12'`. An exception is thrown when the request path
contains illegal characters. Currently, only spaces are rejected but that
Expand Down
4 changes: 4 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ added: v0.3.4
* `allowHalfOpen` {boolean} Indicates whether half-opened TCP connections
are allowed. See [`net.createServer()`][] and the [`'end'`][] event
for details. **Default:** `false`.
* `noDelay` {boolean} A boolean with which to call [`socket.setNoDelay()`][]
when a socket connection is established. This only applies when the
underlying connection is a TCP socket.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default values.

* `readable` {boolean} Allow reads on the socket when an `fd` is passed,
otherwise ignored. **Default:** `false`.
* `writable` {boolean} Allow writes on the socket when an `fd` is passed,
Expand Down Expand Up @@ -1262,6 +1265,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
[`socket.pause()`]: #net_socket_pause
[`socket.resume()`]: #net_socket_resume
[`socket.setEncoding()`]: #net_socket_setencoding_encoding
[`socket.setNoDelay()`]: #net_socket_setnodelay_nodelay
[`socket.setTimeout()`]: #net_socket_settimeout_timeout_callback
[`socket.setTimeout(timeout)`]: #net_socket_settimeout_timeout_callback
[half-closed]: https://tools.ietf.org/html/rfc1122
Expand Down
3 changes: 3 additions & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ function ClientRequest(input, options, cb) {

this.socketPath = options.socketPath;

if (options.noDelay !== undefined)
this._deferToConnect('setNoDelay', [options.noDelay]);

if (options.timeout !== undefined)
this.timeout = getTimerDuration(options.timeout, 'timeout');

Expand Down
4 changes: 4 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ function Socket(options) {
this.server = null;
this._server = null;

if (options.noDelay !== undefined) {
this.setNoDelay(options.noDelay);
}

// Used after `.destroy()`
this[kBytesRead] = 0;
this[kBytesWritten] = 0;
Expand Down