From 844418c544f718949bf3441743d23ab0cc132bb7 Mon Sep 17 00:00:00 2001 From: Rusty Conover Date: Mon, 27 Jan 2020 11:19:05 -0500 Subject: [PATCH 1/2] http: Add noDelay to http.request() options. Add the noDelay option to the http.request() options such that .setNoDelay() will be called once a socket is obtained. Add note about noDelay only applying to a TCP socket. --- doc/api/http.md | 3 +++ lib/_http_client.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/doc/api/http.md b/doc/api/http.md index dd90b54d3e11cb..7aeca4f2ec453a 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -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 diff --git a/lib/_http_client.js b/lib/_http_client.js index fef4b635a00166..453efb88127c6b 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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'); From 24697c2bdab4167ca8240b94832b6b39186d1bb5 Mon Sep 17 00:00:00 2001 From: Rusty Conover Date: Wed, 26 Feb 2020 07:12:25 -0500 Subject: [PATCH 2/2] net: Add noDelay to net.Socket() options Add the noDelay option to the net.Socket() options such that .setNoDelay() will be called when a socket is created --- doc/api/net.md | 4 ++++ lib/net.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/doc/api/net.md b/doc/api/net.md index d04e7eff0789a7..b558a90b124947 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -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. * `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, @@ -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 diff --git a/lib/net.js b/lib/net.js index 11dd4bc900ef9b..4937f7271a35ec 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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;