-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Http proxy support #366
Http proxy support #366
Conversation
Should fix #107 |
if (config.proxy) { | ||
options.host = config.proxy.host; | ||
options.port = config.proxy.port; | ||
options.path = parsed.protocol + '//' + parsed.hostname + options.path; | ||
options.path = parsed.protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path; | ||
} | ||
|
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.
I suggest to refactor this a bit to eliminate duplication:
var proxy = config.proxy;
if (!proxy) {
// try to retrieve proxy settings from env variables
}
if (proxy) {
// override options.host, options.port, and options.path
}
Thank you for the PR! It looks great. I have added some comments, please take a look. |
Thanks for the review. updates coming. |
@nickuraltsev updated! |
var proxyEnv = parsed.protocol.slice(0, -1) + '_proxy'; | ||
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()]; | ||
if (proxyUrl) { | ||
proxy = url.parse(proxyUrl); |
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.
I think we should use the hostname
property of the URL object rather than host
. The latter contains the host name and the port (e.g. 'foo.com:8080'), which is not what should be passed to http.request
(see https://nodejs.org/api/http.html#http_http_request_options_callback).
var parsedProxyUrl = url.parse(proxyUrl);
proxy = {
host: parsedProxyUrl.hostname,
port: parsedProxyUrl.port
};
@bomsy Thank you for the updates! I've just added one more comment. |
@bomsy ping |
fixing the conflict now! |
92e2524
to
65cf8c5
Compare
done! |
Looks like I was not clear enough (sorry for that!). My suggestion was to set the var parsedProxyUrl = url.parse(proxyUrl);
proxy = {
host: parsedProxyUrl.hostname,
port: parsedProxyUrl.port
}; Replacing Thank you for working on this! |
@bomsy Hey! Are you still interested in working on this PR? |
@nickuraltsev hey ... yeah. been busy. will get it out in a bit. |
@nickuraltsev done! |
@bomsy Thank you! |
How do I tell if the version of axios I'm using has this fix? |
var proxy = config.proxy; | ||
if (!proxy) { | ||
var proxyEnv = parsed.protocol.slice(0, -1) + '_proxy'; | ||
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()]; |
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.
can we add change this line to var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()] || process.env.all_proxy || process.env.ALL_PROXY]
so that we can support all_proxy environment variables
process.env.http_proxy / https_proxy / HTTP_PROXY / HTTPS_PROXY