Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 29 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,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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the case of the env variable is not really specified. On Linux most programs use the lower case variant http_proxy (and same for no_proxy). Most programs support either lower or upper case and I think we should also try to use lower-case (preferred) and fallback to upper-case.

// 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually need to split the entries of no_proxy by comma before checking this, since there exist TLD domains, that are the prefix of another. So downloading a plugin from foo.ac would also not use the proxy if your env looks like no_proxy="foo.academy,localhost" even though it should be.

So we should split no_proxy by comma and check for an exact entry.

Also this way we don't support the more complex syntax of no_proxy, with ports and subdomain wildcards. We should think if these are important enough for the beginning that they must be there, or it's a nice to have to implement later.


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');
Expand Down