Skip to content

Commit

Permalink
fix(client): use location protocol on ipv6 any (::) host (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylemkimon authored Nov 27, 2020
1 parent e80f12d commit 47a0fe1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 4 additions & 6 deletions client-src/default/utils/createSocketUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function getSocketUrl(urlParts, loc) {
const { auth, query } = urlParts;
let { hostname, protocol, port } = urlParts;

const isInaddrAny = hostname === '0.0.0.0' || hostname === '::';

if (!port || port === '0') {
port = loc.port;
}
Expand All @@ -51,11 +53,7 @@ function getSocketUrl(urlParts, loc) {
// why do we need this check?
// hostname n/a for file protocol (example, when using electron, ionic)
// see: https://github.com/webpack/webpack-dev-server/pull/384
if (
(hostname === '0.0.0.0' || hostname === '::') &&
loc.hostname &&
loc.protocol.indexOf('http') === 0
) {
if (isInaddrAny && loc.hostname && loc.protocol.indexOf('http') === 0) {
hostname = loc.hostname;
}

Expand All @@ -66,7 +64,7 @@ function getSocketUrl(urlParts, loc) {
if (
hostname &&
hostname !== '127.0.0.1' &&
(loc.protocol === 'https:' || urlParts.hostname === '0.0.0.0')
(loc.protocol === 'https:' || isInaddrAny)
) {
protocol = loc.protocol;
}
Expand Down
2 changes: 2 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('createSocketUrl', () => {
['http://127.0.0.1', 'https://something.com', 'http://127.0.0.1/ws'],
['http://0.0.0.0', 'https://something.com', 'https://something.com/ws'],
['http://0.0.0.0', 'http://something.com', 'http://something.com/ws'],
['http://[::]', 'https://something.com', 'https://something.com/ws'],
['http://example.com', 'http://something.com', 'http://example.com/ws'],
['https://example.com', 'http://something.com', 'https://example.com/ws'],
];
Expand All @@ -69,6 +70,7 @@ describe('createSocketUrl', () => {
['?http://127.0.0.1', 'https://something.com', 'http://127.0.0.1/ws'],
['?http://0.0.0.0', 'https://something.com', 'https://something.com/ws'],
['?http://0.0.0.0', 'http://something.com', 'http://something.com/ws'],
['?http://[::]', 'https://something.com', 'https://something.com/ws'],
['?http://example.com', 'http://something.com', 'http://example.com/ws'],
['?https://example.com', 'http://something.com', 'https://example.com/ws'],
[
Expand Down

0 comments on commit 47a0fe1

Please sign in to comment.