Skip to content

Commit

Permalink
http2: override authority with options
Browse files Browse the repository at this point in the history
Make `options.host` and `options.port` take precedence over
`authority.host` and `authority.port` respectively.

PR-URL: #28584
Fixes: #28182
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
lpinca authored and targos committed Jul 20, 2019
1 parent 9be1111 commit 5b9c227
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Expand Up @@ -2799,7 +2799,7 @@ function connect(authority, options, listener) {
} else { } else {
switch (protocol) { switch (protocol) {
case 'http:': case 'http:':
socket = net.connect(port, host); socket = net.connect(options.port || port, options.host || host);
break; break;
case 'https:': case 'https:':
socket = tls.connect(port, host, initializeTLSOptions(options, host)); socket = tls.connect(port, host, initializeTLSOptions(options, host));
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-http2-connect.js
Expand Up @@ -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();
}));
}));
}

0 comments on commit 5b9c227

Please sign in to comment.