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(); + })); + })); +}