2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Adding support for no_proxy env variable (#1693)

* Adding support for no_proxy env variable

* Adds support for the no_proxy environment variable commonly available
  with programs supporting the http_proxy/https_proxy environment
  variables.
* Adds tests to test the no_proxy environment variable.

* Adding documentation for the proxy env variables

* Adds documentation to README.md for the supported, conventional
  http_proxy, https_proxy, and no_proxy environment variables.
This commit is contained in:
Chance Dickson
2018-08-07 12:52:04 -05:00
committed by Emily Morehouse
parent b9f68bdf00
commit 38de25257c
3 changed files with 119 additions and 10 deletions
+77
View File
@@ -21,6 +21,9 @@ describe('supports http with nodejs', function () {
if (process.env.http_proxy) {
delete process.env.http_proxy;
}
if (process.env.no_proxy) {
delete process.env.no_proxy;
}
});
it('should respect the timeout property', function (done) {
@@ -403,6 +406,80 @@ describe('supports http with nodejs', function () {
});
});
it('should not use proxy for domains in no_proxy', function (done) {
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.end('4567');
}).listen(4444, function () {
proxy = http.createServer(function (request, response) {
var parsed = url.parse(request.url);
var opts = {
host: parsed.hostname,
port: parsed.port,
path: parsed.path
};
http.get(opts, function (res) {
var body = '';
res.on('data', function (data) {
body += data;
});
res.on('end', function () {
response.setHeader('Content-Type', 'text/html; charset=UTF-8');
response.end(body + '1234');
});
});
}).listen(4000, function () {
// set the env variable
process.env.http_proxy = 'http://localhost:4000/';
process.env.no_proxy = 'foo.com, localhost,bar.net , , quix.co';
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, '4567', 'should not use proxy for domains in no_proxy');
done();
});
});
});
});
it('should use proxy for domains not in no_proxy', function (done) {
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.end('4567');
}).listen(4444, function () {
proxy = http.createServer(function (request, response) {
var parsed = url.parse(request.url);
var opts = {
host: parsed.hostname,
port: parsed.port,
path: parsed.path
};
http.get(opts, function (res) {
var body = '';
res.on('data', function (data) {
body += data;
});
res.on('end', function () {
response.setHeader('Content-Type', 'text/html; charset=UTF-8');
response.end(body + '1234');
});
});
}).listen(4000, function () {
// set the env variable
process.env.http_proxy = 'http://localhost:4000/';
process.env.no_proxy = 'foo.com, ,bar.net , quix.co';
axios.get('http://localhost:4444/').then(function (res) {
assert.equal(res.data, '45671234', 'should use proxy for domains not in no_proxy');
done();
});
});
});
});
it('should support HTTP proxy auth', function (done) {
server = http.createServer(function (req, res) {
res.end();