Skip to content

Commit

Permalink
fix: Build fails with TimeOut exception: proxy
Browse files Browse the repository at this point in the history
Closes #585
  • Loading branch information
develar committed Sep 11, 2016
1 parent cb538c1 commit dd61408
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 24 additions & 1 deletion src/util/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`))
Expand Down Expand Up @@ -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
}
})
}

0 comments on commit dd61408

Please sign in to comment.