diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7e6347927962b2..186cb2381935cc 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -932,6 +932,11 @@ The [`require.extensions`][] property is deprecated. -Type: Runtime +Type: Application (non-`node_modules` code only) The [`punycode`][] module is deprecated. Please use a userland alternative instead. diff --git a/doc/api/module.md b/doc/api/module.md index cad96d23476c64..6ed09d996823c0 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -259,12 +259,13 @@ changes: * `'strip'` Only strip type annotations without performing the transformation of TypeScript features. * `sourceUrl` {string} Specifies the source url used in the source map. * Returns: {string} The code with type annotations stripped. - `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It - can be used to strip type annotations from TypeScript code before running it - with `vm.runInContext()` or `vm.compileFunction()`. - By default, it will throw an error if the code contains TypeScript features - that require transformation such as `Enums`, - see [type-stripping][] for more information. + +`module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It +can be used to strip type annotations from TypeScript code before running it +with `vm.runInContext()` or `vm.compileFunction()`. + +By default, it will throw an error if the code contains TypeScript features +that require transformation, such as `enum`s. See [type-stripping][] for more information. _WARNING_: The output of this function should not be considered stable across Node.js versions, due to changes in the TypeScript parser. diff --git a/lib/internal/net.js b/lib/internal/net.js index d380d8a41982e2..80de67791512e4 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -100,6 +100,9 @@ function isLoopback(host) { module.exports = { kReinitializeHandle: Symbol('kReinitializeHandle'), + kSetNoDelay: Symbol('kSetNoDelay'), + kSetKeepAlive: Symbol('kSetKeepAlive'), + kSetKeepAliveInitialDelay: Symbol('kSetKeepAliveInitialDelay'), isIP, isIPv4, isIPv6, diff --git a/lib/internal/tls/wrap.js b/lib/internal/tls/wrap.js index 7a1752649c4277..308180d483908d 100644 --- a/lib/internal/tls/wrap.js +++ b/lib/internal/tls/wrap.js @@ -590,6 +590,9 @@ function TLSSocket(socket, opts) { highWaterMark: tlsOptions.highWaterMark, onread: !socket ? tlsOptions.onread : null, signal: tlsOptions.signal, + noDelay: tlsOptions.noDelay, + keepAlive: tlsOptions.keepAlive, + keepAliveInitialDelay: tlsOptions.keepAliveInitialDelay, }); // Proxy for API compatibility @@ -1755,6 +1758,9 @@ exports.connect = function connect(...args) { highWaterMark: options.highWaterMark, onread: options.onread, signal: options.signal, + noDelay: options.noDelay, + keepAlive: options.keepAlive, + keepAliveInitialDelay: options.keepAliveInitialDelay, }); // rejectUnauthorized property can be explicitly defined as `undefined` diff --git a/lib/net.js b/lib/net.js index e22ef4bfc4bff0..efd2029fb67ddd 100644 --- a/lib/net.js +++ b/lib/net.js @@ -48,6 +48,9 @@ let debug = require('internal/util/debuglog').debuglog('net', (fn) => { }); const { kReinitializeHandle, + kSetNoDelay, + kSetKeepAlive, + kSetKeepAliveInitialDelay, isIP, isIPv4, isIPv6, @@ -356,9 +359,6 @@ function closeSocketHandle(self, isException, isCleanupPending = false) { const kBytesRead = Symbol('kBytesRead'); const kBytesWritten = Symbol('kBytesWritten'); -const kSetNoDelay = Symbol('kSetNoDelay'); -const kSetKeepAlive = Symbol('kSetKeepAlive'); -const kSetKeepAliveInitialDelay = Symbol('kSetKeepAliveInitialDelay'); const kSetTOS = Symbol('kSetTOS'); function Socket(options) { diff --git a/test/parallel/test-tls-connect-keepalive-nodelay.js b/test/parallel/test-tls-connect-keepalive-nodelay.js new file mode 100644 index 00000000000000..81eaafabc64a6f --- /dev/null +++ b/test/parallel/test-tls-connect-keepalive-nodelay.js @@ -0,0 +1,65 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); + +// This test verifies that tls.connect() forwards keepAlive, +// keepAliveInitialDelay, and noDelay options to the underlying socket. + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const tls = require('tls'); +const fixtures = require('../common/fixtures'); +const { + kSetNoDelay, + kSetKeepAlive, + kSetKeepAliveInitialDelay, +} = require('internal/net'); + +const key = fixtures.readKey('agent1-key.pem'); +const cert = fixtures.readKey('agent1-cert.pem'); + +// Test: keepAlive, keepAliveInitialDelay, and noDelay +{ + const server = tls.createServer({ key, cert }, (socket) => { + socket.end(); + }); + + server.listen(0, common.mustCall(() => { + const socket = tls.connect({ + port: server.address().port, + rejectUnauthorized: false, + keepAlive: true, + keepAliveInitialDelay: 1000, + noDelay: true, + }, common.mustCall(() => { + assert.strictEqual(socket[kSetKeepAlive], true); + assert.strictEqual(socket[kSetKeepAliveInitialDelay], 1); + assert.strictEqual(socket[kSetNoDelay], true); + socket.destroy(); + server.close(); + })); + })); +} + +// Test: defaults (options not set) +{ + const server = tls.createServer({ key, cert }, (socket) => { + socket.end(); + }); + + server.listen(0, common.mustCall(() => { + const socket = tls.connect({ + port: server.address().port, + rejectUnauthorized: false, + }, common.mustCall(() => { + assert.strictEqual(socket[kSetKeepAlive], false); + assert.strictEqual(socket[kSetKeepAliveInitialDelay], 0); + assert.strictEqual(socket[kSetNoDelay], false); + socket.destroy(); + server.close(); + })); + })); +}