Skip to content

Commit e600fbe

Browse files
committed
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 2767209 commit e600fbe

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

doc/api/tls.md

+5
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ decrease overall server throughput.
752752
<!-- YAML
753753
added: v0.11.3
754754
changes:
755+
- version: REPLACEME
756+
pr-url: https://github.com/nodejs/node/pull/12839
757+
description: The `lookup` option is supported now.
755758
- version: REPLACEME
756759
pr-url: https://github.com/nodejs/node/pull/11984
757760
description: The `ALPNProtocols` and `NPNProtocols` options can
@@ -809,6 +812,7 @@ changes:
809812
`tls.createSecureContext()`. *Note*: In effect, all
810813
[`tls.createSecureContext()`][] options can be provided, but they will be
811814
_completely ignored_ unless the `secureContext` option is missing.
815+
* `lookup`: {Function} Custom lookup function. Defaults to [`dns.lookup()`][].
812816
* ...: Optional [`tls.createSecureContext()`][] options can be provided, see
813817
the `secureContext` option for more information.
814818
* `callback` {Function}
@@ -1291,3 +1295,4 @@ where `secure_socket` has the same API as `pair.cleartext`.
12911295
[modifying the default cipher suite]: #tls_modifying_the_default_tls_cipher_suite
12921296
[specific attacks affecting larger AES key sizes]: https://www.schneier.com/blog/archives/2009/07/another_new_aes.html
12931297
[tls.Server]: #tls_class_tls_server
1298+
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback

lib/_tls_wrap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
10631063
port: options.port,
10641064
host: options.host,
10651065
family: options.family,
1066-
localAddress: options.localAddress
1066+
localAddress: options.localAddress,
1067+
lookup: options.lookup
10671068
};
10681069
}
10691070
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)