diff --git a/README.md b/README.md index 5b3c9137f6..b4bfbe8a4a 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,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 `Proxy-Authorization` custom headers you have set using `headers`. proxy: { @@ -526,7 +528,7 @@ In a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/ var params = new URLSearchParams(); params.append('param1', 'value1'); params.append('param2', 'value2'); -axios.post('/foo', params); +axios.post('/foo', params); ``` > Note that `URLSearchParams` is not supported by all browsers, but there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment). diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8a2fc57dac..b552b73549 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -82,7 +82,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 131bce0032..816c517c38 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -286,6 +286,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');