Skip to content

Commit 00b2790

Browse files
indutnyMylesBorins
authored andcommitted
tls: accept lookup option for tls.connect()
`net.connect()` and consequently `http.Agent` support custom DNS `lookup` option. However, as we move to `https.Agent` - this option no longer works because it is not proxied by `tls.connect`. Fix this inconsistency by passing it down to `net.connect`. PR-URL: #12839 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent a09e2fd commit 00b2790

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

doc/api/tls.md

+6
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,10 @@ argument.
777777
## tls.connect(options[, callback])
778778
<!-- YAML
779779
added: v0.11.3
780+
changes:
781+
- version: REPLACEME
782+
pr-url: https://github.com/nodejs/node/pull/12839
783+
description: The `lookup` option is supported now.
780784
-->
781785

782786
* `options` {Object}
@@ -823,6 +827,7 @@ added: v0.11.3
823827
`tls.createSecureContext()`. *Note*: In effect, all
824828
[`tls.createSecureContext()`][] options can be provided, but they will be
825829
_completely ignored_ unless the `secureContext` option is missing.
830+
* `lookup`: {Function} Custom lookup function. Defaults to [`dns.lookup()`][].
826831
* ...: Optional [`tls.createSecureContext()`][] options can be provided, see
827832
the `secureContext` option for more information.
828833
* `callback` {Function}
@@ -1243,3 +1248,4 @@ where `secure_socket` has the same API as `pair.cleartext`.
12431248
[modifying the default cipher suite]: #tls_modifying_the_default_tls_cipher_suite
12441249
[specific attacks affecting larger AES key sizes]: https://www.schneier.com/blog/archives/2009/07/another_new_aes.html
12451250
[tls.Server]: #tls_class_tls_server
1251+
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback

lib/_tls_wrap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ exports.connect = function(/* [port,] [host,] [options,] [cb] */) {
10571057
port: options.port,
10581058
host: options.host,
10591059
family: options.family,
1060-
localAddress: options.localAddress
1060+
localAddress: options.localAddress,
1061+
lookup: options.lookup
10611062
};
10621063
}
10631064
socket.connect(connect_opt, function() {

test/parallel/test-tls-lookup.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const tls = require('tls');
5+
6+
const expectedError = /^TypeError: "lookup" option should be a function$/;
7+
8+
['foobar', 1, {}, []].forEach(function connectThrows(input) {
9+
const opts = {
10+
host: 'localhost',
11+
port: common.PORT,
12+
lookup: input
13+
};
14+
15+
assert.throws(function() {
16+
tls.connect(opts);
17+
}, expectedError);
18+
});
19+
20+
connectDoesNotThrow(common.mustCall(() => {}));
21+
22+
function connectDoesNotThrow(input) {
23+
const opts = {
24+
host: 'localhost',
25+
port: common.PORT,
26+
lookup: input
27+
};
28+
29+
assert.doesNotThrow(function() {
30+
tls.connect(opts);
31+
});
32+
}

0 commit comments

Comments
 (0)