Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd4d1e2

Browse filesBrowse files
lpincatargos
authored andcommitted
http2: remove square brackets from parsed hostname
Make `http2.connect()` work when using URLs with literal IPv6 addresses. Fixes: #28216 PR-URL: #28406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent 0111c61 commit fd4d1e2
Copy full SHA for fd4d1e2

File tree

Expand file treeCollapse file tree

2 files changed

+39
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,16 @@ function connect(authority, options, listener) {
27822782
const protocol = authority.protocol || options.protocol || 'https:';
27832783
const port = '' + (authority.port !== '' ?
27842784
authority.port : (authority.protocol === 'http:' ? 80 : 443));
2785-
const host = authority.hostname || authority.host || 'localhost';
2785+
let host = 'localhost';
2786+
2787+
if (authority.hostname) {
2788+
host = authority.hostname;
2789+
2790+
if (host[0] === '[')
2791+
host = host.slice(1, -1);
2792+
} else if (authority.host) {
2793+
host = authority.host;
2794+
}
27862795

27872796
let socket;
27882797
if (typeof options.createConnection === 'function') {
Collapse file

‎test/parallel/test-http2-connect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-connect.js
+29-1Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use strict';
22

3-
const { mustCall, hasCrypto, skip, expectsError } = require('../common');
3+
const {
4+
mustCall,
5+
hasCrypto,
6+
hasIPv6,
7+
skip,
8+
expectsError
9+
} = require('../common');
410
if (!hasCrypto)
511
skip('missing crypto');
612
const { createServer, connect } = require('http2');
@@ -73,3 +79,25 @@ const { connect: netConnect } = require('net');
7379
type: Error
7480
});
7581
}
82+
83+
// Check for literal IPv6 addresses in URL's
84+
if (hasIPv6) {
85+
const server = createServer();
86+
server.listen(0, '::1', mustCall(() => {
87+
const { port } = server.address();
88+
const clients = new Set();
89+
90+
clients.add(connect(`http://[::1]:${port}`));
91+
clients.add(connect(new URL(`http://[::1]:${port}`)));
92+
93+
for (const client of clients) {
94+
client.once('connect', mustCall(() => {
95+
client.close();
96+
clients.delete(client);
97+
if (clients.size === 0) {
98+
server.close();
99+
}
100+
}));
101+
}
102+
}));
103+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.