Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10e0d7f

Browse filesBrowse files
lpincatargos
authored andcommitted
tls: support the hints option
Make `tls.connect()` support the `hints` option for feature parity with `net.connect()`. PR-URL: #27816 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 6981565 commit 10e0d7f
Copy full SHA for 10e0d7f

File tree

Expand file treeCollapse file tree

3 files changed

+33
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+33
-19
lines changed
Open diff view settings
Collapse file

‎doc/api/tls.md‎

Copy file name to clipboardExpand all lines: doc/api/tls.md
+5-7Lines changed: 5 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,9 @@ being issued by trusted CA (`options.ca`).
11781178
<!-- YAML
11791179
added: v0.11.3
11801180
changes:
1181+
- version: REPLACEME
1182+
pr-url: https://github.com/nodejs/node/pull/27816
1183+
description: The `hints` option is now supported.
11811184
- version: v12.2.0
11821185
pr-url: https://github.com/nodejs/node/pull/27497
11831186
description: The `enableTrace` option is now supported.
@@ -1248,13 +1251,9 @@ changes:
12481251
[`tls.createSecureContext()`][]. If a `secureContext` is _not_ provided, one
12491252
will be created by passing the entire `options` object to
12501253
`tls.createSecureContext()`.
1251-
* `lookup`: {Function} Custom lookup function. **Default:**
1252-
[`dns.lookup()`][].
1253-
* `timeout`: {number} If set and if a socket is created internally, will call
1254-
[`socket.setTimeout(timeout)`][] after the socket is created, but before it
1255-
starts the connection.
12561254
* ...: [`tls.createSecureContext()`][] options that are used if the
12571255
`secureContext` option is missing, otherwise they are ignored.
1256+
* ...: Any [`socket.connect()`][] option not already listed.
12581257
* `callback` {Function}
12591258
* Returns: {tls.TLSSocket}
12601259

@@ -1771,7 +1770,6 @@ where `secureSocket` has the same API as `pair.cleartext`.
17711770
[`--tls-cipher-list`]: cli.html#cli_tls_cipher_list_list
17721771
[`NODE_OPTIONS`]: cli.html#cli_node_options_options
17731772
[`crypto.getCurves()`]: crypto.html#crypto_crypto_getcurves
1774-
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback
17751773
[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener
17761774
[`net.Server.address()`]: net.html#net_server_address
17771775
[`net.Server`]: net.html#net_class_net_server
@@ -1781,7 +1779,7 @@ where `secureSocket` has the same API as `pair.cleartext`.
17811779
[`server.getTicketKeys()`]: #tls_server_getticketkeys
17821780
[`server.listen()`]: net.html#net_server_listen
17831781
[`server.setTicketKeys()`]: #tls_server_setticketkeys_keys
1784-
[`socket.setTimeout(timeout)`]: #net_socket_settimeout_timeout_callback
1782+
[`socket.connect()`]: net.html#net_socket_connect_options_connectlistener
17851783
[`tls.DEFAULT_ECDH_CURVE`]: #tls_tls_default_ecdh_curve
17861784
[`tls.DEFAULT_MAX_VERSION`]: #tls_tls_default_max_version
17871785
[`tls.DEFAULT_MIN_VERSION`]: #tls_tls_default_min_version
Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+2-12Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,23 +1420,13 @@ exports.connect = function connect(...args) {
14201420
tlssock.once('secureConnect', cb);
14211421

14221422
if (!options.socket) {
1423-
// If user provided the socket, its their responsibility to manage its
1423+
// If user provided the socket, it's their responsibility to manage its
14241424
// connectivity. If we created one internally, we connect it.
1425-
const connectOpt = {
1426-
path: options.path,
1427-
port: options.port,
1428-
host: options.host,
1429-
family: options.family,
1430-
localAddress: options.localAddress,
1431-
localPort: options.localPort,
1432-
lookup: options.lookup
1433-
};
1434-
14351425
if (options.timeout) {
14361426
tlssock.setTimeout(options.timeout);
14371427
}
14381428

1439-
tlssock.connect(connectOpt, tlssock._start);
1429+
tlssock.connect(options, tlssock._start);
14401430
}
14411431

14421432
tlssock._releaseControl();
Collapse file
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
// This test verifies that `tls.connect()` honors the `hints` option.
6+
7+
if (!common.hasCrypto)
8+
common.skip('missing crypto');
9+
10+
const assert = require('assert');
11+
const dns = require('dns');
12+
const tls = require('tls');
13+
14+
const hints = 512;
15+
16+
assert.notStrictEqual(hints, dns.ADDRCONFIG);
17+
assert.notStrictEqual(hints, dns.V4MAPPED);
18+
assert.notStrictEqual(hints, dns.ADDRCONFIG | dns.V4MAPPED);
19+
20+
tls.connect({
21+
lookup: common.mustCall((host, options) => {
22+
assert.strictEqual(host, 'localhost');
23+
assert.deepStrictEqual(options, { family: undefined, hints });
24+
}),
25+
hints
26+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.