From 1a676b5dcd9c6312d08095c9e3361505461bb3f4 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 4 May 2017 19:05:35 -0400 Subject: [PATCH 1/4] 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`. --- doc/api/tls.md | 1 + lib/_tls_wrap.js | 3 ++- test/parallel/test-tls-lookup.js | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-tls-lookup.js diff --git a/doc/api/tls.md b/doc/api/tls.md index a11631b0134520..a383ad7f95e12d 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -809,6 +809,7 @@ changes: `tls.createSecureContext()`. *Note*: In effect, all [`tls.createSecureContext()`][] options can be provided, but they will be _completely ignored_ unless the `secureContext` option is missing. + * `lookup`: {Function} Custom lookup function. Defaults to [`dns.lookup()`][]. * ...: Optional [`tls.createSecureContext()`][] options can be provided, see the `secureContext` option for more information. * `callback` {Function} diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 511ff3557a6e23..1a827b37171007 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1066,7 +1066,8 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) { port: options.port, host: options.host, family: options.family, - localAddress: options.localAddress + localAddress: options.localAddress, + lookup: options.lookup }; } socket.connect(connect_opt, function() { diff --git a/test/parallel/test-tls-lookup.js b/test/parallel/test-tls-lookup.js new file mode 100644 index 00000000000000..571ed556a6816f --- /dev/null +++ b/test/parallel/test-tls-lookup.js @@ -0,0 +1,34 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const tls = require('tls'); + +const expectedError = /^TypeError: "lookup" option should be a function$/; + +['foobar', 1, {}, []].forEach((input) => connectThrows(input)); + +function connectThrows(input) { + const opts = { + host: 'localhost', + port: common.PORT, + lookup: input + }; + + assert.throws(function() { + tls.connect(opts); + }, expectedError); +} + +connectDoesNotThrow(common.mustCall(common.noop)); + +function connectDoesNotThrow(input) { + const opts = { + host: 'localhost', + port: common.PORT, + lookup: input + }; + + assert.doesNotThrow(function() { + tls.connect(opts); + }); +} From cfdb7ef72c82853e6e76d1825aa22496f1d56826 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sat, 6 May 2017 15:17:05 -0400 Subject: [PATCH 2/4] fix --- doc/api/tls.md | 3 +++ test/parallel/test-tls-lookup.js | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/api/tls.md b/doc/api/tls.md index a383ad7f95e12d..4a6ffed7a13e25 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -752,6 +752,9 @@ decrease overall server throughput.