Skip to content

Commit

Permalink
Fixes elastic#5211
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Vendetta committed Mar 29, 2017
1 parent 2cc8368 commit de65b36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@
"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",
"gridster": "0.5.6",
"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",
Expand Down
32 changes: 31 additions & 1 deletion src/cli_plugin/install/downloaders/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@ 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);
} else {
return false;
}
} else {
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');
Expand Down

0 comments on commit de65b36

Please sign in to comment.