-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Plugin installer proxy support #10946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually need to split the entries of So we should split Also this way we don't support the more complex syntax of |
||
|
|
||
| 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'); | ||
|
|
||
There was a problem hiding this comment.
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 forno_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.