From 0369fea1d38bb1939ce2ee703f635fc9f5686a03 Mon Sep 17 00:00:00 2001 From: Rafael Morales Date: Wed, 13 Feb 2019 22:13:09 -0300 Subject: [PATCH] Fix for basic-auth servers connect (#1074) --- src/scripts/servers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scripts/servers.js b/src/scripts/servers.js index b64be4b5b1..cfcc72bb8a 100644 --- a/src/scripts/servers.js +++ b/src/scripts/servers.js @@ -126,8 +126,16 @@ class Servers extends EventEmitter { } async validateHost(hostUrl, timeout = 5000) { + const headers = new Headers(); + + if (hostUrl.includes('@')) { + const url = new URL(hostUrl); + hostUrl = url.origin; + headers.set('Authorization', `Basic ${ btoa(`${ url.username }:${ url.password }`) }`); + } + const response = await Promise.race([ - fetch(`${ hostUrl }/api/info`), + fetch(`${ hostUrl }/api/info`, { headers }), new Promise((resolve, reject) => setTimeout(() => reject('timeout'), timeout)), ]);