From 7faf1c9030cc5bf509f39fcb5e4a0bf23cbb8626 Mon Sep 17 00:00:00 2001 From: david weil Date: Mon, 10 Jun 2019 05:11:01 -0300 Subject: [PATCH] fix(BrowserFetcher): fix httpRequest when using proxy against http HOST (#4558) This patch avoids https-proxy-agent usage when target host protocol is http and proxy is specified. This is a valid scenario for installer but was failing. Fixes #4556 --- lib/BrowserFetcher.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/BrowserFetcher.js b/lib/BrowserFetcher.js index 4433df9f..4f0492bd 100644 --- a/lib/BrowserFetcher.js +++ b/lib/BrowserFetcher.js @@ -268,17 +268,26 @@ function extractZip(zipPath, folderPath) { function httpRequest(url, method, response) { /** @type {Object} */ - const options = URL.parse(url); + let options = URL.parse(url); options.method = method; const proxyURL = getProxyForUrl(url); if (proxyURL) { - /** @type {Object} */ - const parsedProxyURL = URL.parse(proxyURL); - parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:'; + if (url.startsWith('http:')) { + const proxy = URL.parse(proxyURL); + options = { + path: options.href, + host: proxy.hostname, + port: proxy.port, + }; + } else { + /** @type {Object} */ + const parsedProxyURL = URL.parse(proxyURL); + parsedProxyURL.secureProxy = parsedProxyURL.protocol === 'https:'; - options.agent = new ProxyAgent(parsedProxyURL); - options.rejectUnauthorized = false; + options.agent = new ProxyAgent(parsedProxyURL); + options.rejectUnauthorized = false; + } } const requestCallback = res => {