diff --git a/package.json b/package.json index a1892dc7b4a9f..e09c0083d0b68 100644 --- a/package.json +++ b/package.json @@ -129,8 +129,8 @@ "expose-loader": "0.7.0", "extract-text-webpack-plugin": "0.8.2", "file-loader": "0.8.4", - "font-awesome": "4.4.0", "flot-charts": "0.8.3", + "font-awesome": "4.4.0", "glob": "5.0.13", "glob-all": "3.0.1", "good-squeeze": "2.1.0", @@ -138,6 +138,7 @@ "h2o2": "5.1.1", "handlebars": "4.0.5", "hapi": "14.2.0", + "http-proxy-agent": "1.0.0", "imports-loader": "0.6.4", "inert": "4.0.2", "jade": "1.11.0", diff --git a/src/cli_plugin/install/downloaders/http.js b/src/cli_plugin/install/downloaders/http.js index f8c28d65b7733..f179a2ebd807c 100644 --- a/src/cli_plugin/install/downloaders/http.js +++ b/src/cli_plugin/install/downloaders/http.js @@ -2,11 +2,39 @@ import Wreck from 'wreck'; import Progress from '../progress'; import { fromNode as fn } from 'bluebird'; import { createWriteStream } from 'fs'; +import HttpProxyAgent from 'http-proxy-agent'; +import URL from 'url'; + +function getProxyAgent(sourceUrl) { + const httpProxy = process.env.HTTP_PROXY; + // we have a proxy detected, lets use it + if (httpProxy && httpProxy !== '') { + // get the hostname of the sourceUrl + const hostname = URL.parse(sourceUrl).hostname; + const noProxy = process.env.NO_PROXY || ''; + + // proxy if the hostname is not in noProxy + const shouldProxy = (noProxy.indexOf(hostname) === -1); + + if (shouldProxy) { + return new HttpProxyAgent(httpProxy); + } + } + + return false; +} function sendRequest({ sourceUrl, timeout }) { const maxRedirects = 11; //Because this one goes to 11. return fn(cb => { - const req = Wreck.request('GET', sourceUrl, { timeout, redirects: maxRedirects }, (err, resp) => { + const reqOptions = { timeout, redirects: maxRedirects }; + const proxyAgent = getProxyAgent(sourceUrl); + + if (proxyAgent) { + reqOptions.agent = proxyAgent; + } + + const req = Wreck.request('GET', sourceUrl, reqOptions, (err, resp) => { if (err) { if (err.code === 'ECONNREFUSED') { err = new Error('ENOTFOUND');