From e800f9d68a3d949cd2bcea741638cfa8e42f3461 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 7 Jul 2019 07:59:44 +0200 Subject: [PATCH] http2: override authority with options Make `options.host` and `options.port` take precedence over `authority.host` and `authority.port` respectively. PR-URL: https://github.com/nodejs/node/pull/28584 Fixes: https://github.com/nodejs/node/issues/28182 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Franziska Hinkelmann Reviewed-By: Trivikram Kamat --- lib/internal/http2/core.js | 2 +- test/parallel/test-http2-connect.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index a65dbb92c5310e..ec720da71ee008 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -2795,7 +2795,7 @@ function connect(authority, options, listener) { } else { switch (protocol) { case 'http:': - socket = net.connect(port, host); + socket = net.connect(options.port || port, options.host || host); break; case 'https:': socket = tls.connect(port, host, initializeTLSOptions(options, host)); diff --git a/test/parallel/test-http2-connect.js b/test/parallel/test-http2-connect.js index 2137ef28926726..a1291e3be956e1 100644 --- a/test/parallel/test-http2-connect.js +++ b/test/parallel/test-http2-connect.js @@ -101,3 +101,18 @@ if (hasIPv6) { } })); } + +// Check that `options.host` and `options.port` take precedence over +// `authority.host` and `authority.port`. +{ + const server = createServer(); + server.listen(0, mustCall(() => { + connect('http://foo.bar', { + host: 'localhost', + port: server.address().port + }, mustCall((session) => { + session.close(); + server.close(); + })); + })); +}