From ba594bb57e7e556a30810a2ac7a0264b05a51a94 Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Wed, 8 Feb 2017 00:47:53 +0100 Subject: [PATCH 1/2] Adding a way to disable all proxy processing 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 --- README.md | 2 ++ lib/adapters/http.js | 2 +- test/unit/adapters/http.js | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f48ea588c7..c4d4a7ae6b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 3048e577b1..ac8cc1efbe 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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) { diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index ba0ecf9c76..ae8238b433 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -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'); From db8457ceda63cc9fbdb493e34ffc4a44ed8813e5 Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Sat, 12 Aug 2017 21:20:20 +0200 Subject: [PATCH 2/2] Change readme wording From review comment on PR (#691) --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index c4d4a7ae6b..e9f4ce727a 100644 --- a/README.md +++ b/README.md @@ -318,8 +318,7 @@ 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. + // Use `false` to disable proxies, ignoring environment variables. // `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