From dd614085216fc132389ff999903b2eee2916c387 Mon Sep 17 00:00:00 2001 From: develar Date: Sun, 11 Sep 2016 11:55:51 +0200 Subject: [PATCH] fix: Build fails with TimeOut exception: proxy Closes #585 --- package.json | 1 + src/util/httpRequest.ts | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d04d964731..68985383587 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "sanitize-filename": "^1.6.0", "semver": "^5.3.0", "source-map-support": "^0.4.2", + "tunnel-agent": "^0.4.3", "update-notifier": "^1.0.2", "uuid-1345": "^0.99.6", "yargs": "^5.0.0" diff --git a/src/util/httpRequest.ts b/src/util/httpRequest.ts index 1b9ef977053..45155b6f49c 100644 --- a/src/util/httpRequest.ts +++ b/src/util/httpRequest.ts @@ -44,7 +44,8 @@ function doDownload(url: string, destination: string, redirectCount: number, opt path: parsedUrl.path, headers: { "User-Agent": "electron-builder" - } + }, + agent: createAgent("https"), }, (response: IncomingMessage) => { if (response.statusCode >= 400) { callback(new Error(`Cannot download "${url}", status ${response.statusCode}: ${response.statusMessage}`)) @@ -121,4 +122,26 @@ class DigestTransform extends Transform { const hash = this.digester.digest("hex") callback(hash === this.expected ? null : new Error(`SHA2 checksum mismatch, expected ${this.expected}, got ${hash}`)) } +} + +function createAgent(uriProtocol: string) { + const proxyString: string = process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy + + if (!proxyString) { + return null + } + + const proxy = parseUrl(proxyString) + + const proxyProtocol = proxy.protocol === "https:" ? "Https" : "Http" + return require("tunnel-agent")[`${uriProtocol}Over${proxyProtocol}`]({ + proxy: { + port: proxy.port || (proxyProtocol === "Https" ? 443 : 80), + host: proxy.hostname, + proxyAuth: proxy.auth + } + }) } \ No newline at end of file