Skip to content

Commit 47a0fe1

Browse files
authored
fix(client): use location protocol on ipv6 any (::) host (#2868)
1 parent e80f12d commit 47a0fe1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

client-src/default/utils/createSocketUrl.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function getSocketUrl(urlParts, loc) {
4343
const { auth, query } = urlParts;
4444
let { hostname, protocol, port } = urlParts;
4545

46+
const isInaddrAny = hostname === '0.0.0.0' || hostname === '::';
47+
4648
if (!port || port === '0') {
4749
port = loc.port;
4850
}
@@ -51,11 +53,7 @@ function getSocketUrl(urlParts, loc) {
5153
// why do we need this check?
5254
// hostname n/a for file protocol (example, when using electron, ionic)
5355
// see: https://github.com/webpack/webpack-dev-server/pull/384
54-
if (
55-
(hostname === '0.0.0.0' || hostname === '::') &&
56-
loc.hostname &&
57-
loc.protocol.indexOf('http') === 0
58-
) {
56+
if (isInaddrAny && loc.hostname && loc.protocol.indexOf('http') === 0) {
5957
hostname = loc.hostname;
6058
}
6159

@@ -66,7 +64,7 @@ function getSocketUrl(urlParts, loc) {
6664
if (
6765
hostname &&
6866
hostname !== '127.0.0.1' &&
69-
(loc.protocol === 'https:' || urlParts.hostname === '0.0.0.0')
67+
(loc.protocol === 'https:' || isInaddrAny)
7068
) {
7169
protocol = loc.protocol;
7270
}

test/client/utils/createSocketUrl.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('createSocketUrl', () => {
4343
['http://127.0.0.1', 'https://something.com', 'http://127.0.0.1/ws'],
4444
['http://0.0.0.0', 'https://something.com', 'https://something.com/ws'],
4545
['http://0.0.0.0', 'http://something.com', 'http://something.com/ws'],
46+
['http://[::]', 'https://something.com', 'https://something.com/ws'],
4647
['http://example.com', 'http://something.com', 'http://example.com/ws'],
4748
['https://example.com', 'http://something.com', 'https://example.com/ws'],
4849
];
@@ -69,6 +70,7 @@ describe('createSocketUrl', () => {
6970
['?http://127.0.0.1', 'https://something.com', 'http://127.0.0.1/ws'],
7071
['?http://0.0.0.0', 'https://something.com', 'https://something.com/ws'],
7172
['?http://0.0.0.0', 'http://something.com', 'http://something.com/ws'],
73+
['?http://[::]', 'https://something.com', 'https://something.com/ws'],
7274
['?http://example.com', 'http://something.com', 'http://example.com/ws'],
7375
['?https://example.com', 'http://something.com', 'https://example.com/ws'],
7476
[

0 commit comments

Comments
 (0)