Skip to content

Commit

Permalink
Adding a way to disable all proxy processing
Browse files Browse the repository at this point in the history
When the proxy field in configuration is === false all proxy processing is
disabled. This specifically disable the 'http_proxy' environment variable
handling.

Fixes #635
Related to #434
  • Loading branch information
vbfox committed Apr 28, 2017
1 parent f31317a commit ba594bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -318,6 +318,8 @@ These are the available config options for making requests. Only the `url` is re
httpsAgent: new https.Agent({ keepAlive: true }),

// 'proxy' defines the hostname and port of the proxy server
// On node the proxy can also come from the 'http_proxy' environment variable.
// Use false to disable all proxy handling.
// `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
// supplies credentials.
// This will set an `Proxy-Authorization` header, overwriting any existing
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/http.js
Expand Up @@ -84,7 +84,7 @@ module.exports = function httpAdapter(config) {
};

var proxy = config.proxy;
if (!proxy) {
if (!proxy && proxy !== false) {
var proxyEnv = protocol.slice(0, -1) + '_proxy';
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
if (proxyUrl) {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -311,6 +311,23 @@ module.exports = {
});
},

testHTTPProxyDisabled: function(test) {
// set the env variable
process.env.http_proxy = 'http://does-not-exists.example.com:4242/';

server = http.createServer(function(req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.end('123456789');
}).listen(4444, function() {
axios.get('http://localhost:4444/', {
proxy: false
}).then(function(res) {
test.equal(res.data, '123456789', 'should not pass through proxy');
test.done();
});
});
},

testHTTPProxyEnv: function(test) {
server = http.createServer(function(req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
Expand Down

0 comments on commit ba594bb

Please sign in to comment.