Skip to content

Commit e800f9d

Browse files
committed
http2: override authority with options
Make `options.host` and `options.port` take precedence over `authority.host` and `authority.port` respectively. PR-URL: #28584 Fixes: #28182 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent fe4d53d commit e800f9d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/http2/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ function connect(authority, options, listener) {
27952795
} else {
27962796
switch (protocol) {
27972797
case 'http:':
2798-
socket = net.connect(port, host);
2798+
socket = net.connect(options.port || port, options.host || host);
27992799
break;
28002800
case 'https:':
28012801
socket = tls.connect(port, host, initializeTLSOptions(options, host));

test/parallel/test-http2-connect.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,18 @@ if (hasIPv6) {
101101
}
102102
}));
103103
}
104+
105+
// Check that `options.host` and `options.port` take precedence over
106+
// `authority.host` and `authority.port`.
107+
{
108+
const server = createServer();
109+
server.listen(0, mustCall(() => {
110+
connect('http://foo.bar', {
111+
host: 'localhost',
112+
port: server.address().port
113+
}, mustCall((session) => {
114+
session.close();
115+
server.close();
116+
}));
117+
}));
118+
}

0 commit comments

Comments
 (0)