Permalink
Browse files

http#proxy now handles HTTP_PROXY and HTTPS_PROXY along with http_pro…

…xy and https_proxy environment variables.
  • Loading branch information...
1 parent 72f308c commit 9ae0c4b9d1ff82c8dce136b631c4d4235b7ca37b @cliffano committed Feb 27, 2013
Showing with 23 additions and 3 deletions.
  1. +1 −1 CHANGELOG.md
  2. +2 −2 lib/http.js
  3. +20 −0 test/http.js
View
2 CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.1.2-pre
-*
+* http#proxy now handles HTTP_PROXY and HTTPS_PROXY along with http_proxy and https_proxy environment variables
### 0.1.1
* Add http#proxy, modify http#request to use environment variable proxy when not specified in opts
View
4 lib/http.js
@@ -51,14 +51,14 @@ function proxy(url) {
var _proxy;
if (!url) {
- _proxy = process.env.http_proxy || process.env.https_proxy;
+ _proxy = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY;
} else {
if (!url.match(/^https?:\/\//)) {
url += 'http://' + url;
}
if (url.match(/^https:\/\//)) {
- _proxy = process.env.https_proxy || process.env.http_proxy;
+ _proxy = process.env.https_proxy || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.HTTP_PROXY;
} else {
_proxy = process.env.http_proxy;
}
View
20 test/http.js
@@ -84,10 +84,18 @@ buster.testCase('http - proxy', {
this.stub(process, 'env', { http_proxy: 'http://someproxy', https_proxy: 'https://someproxy' });
assert.equals(http.proxy('https://someurl'), 'https://someproxy');
},
+ 'should return https proxy when url uses https and both http and HTTPS PROXY exist': function () {
+ this.stub(process, 'env', { http_proxy: 'http://someproxy', HTTPS_PROXY: 'https://someproxy' });
+ assert.equals(http.proxy('https://someurl'), 'https://someproxy');
+ },
'should return http proxy when url uses https and http proxy exists but not https proxy': function () {
this.stub(process, 'env', { http_proxy: 'http://someproxy' });
assert.equals(http.proxy('https://someurl'), 'http://someproxy');
},
+ 'should return http proxy when url uses https and HTTP PROXY exists but not https proxy': function () {
+ this.stub(process, 'env', { HTTP_PROXY: 'http://someproxy' });
+ assert.equals(http.proxy('https://someurl'), 'http://someproxy');
+ },
'should return undefined when url uses https and no proxy environment variable exist': function () {
this.stub(process, 'env', {});
assert.equals(http.proxy('http://someurl'), undefined);
@@ -112,10 +120,22 @@ buster.testCase('http - proxy', {
this.stub(process, 'env', { http_proxy: 'http://someproxy' });
assert.equals(http.proxy(), 'http://someproxy');
},
+ 'should return http proxy when url is not specified and HTTP PROXY exists but not https proxy': function () {
+ this.stub(process, 'env', { HTTP_PROXY: 'http://someproxy' });
+ assert.equals(http.proxy(), 'http://someproxy');
+ },
'should return https proxy when url is not specified and https proxy exists but not http proxy': function () {
this.stub(process, 'env', { https_proxy: 'https://someproxy' });
assert.equals(http.proxy(), 'https://someproxy');
},
+ 'should return http proxy when url is not specified and HTTP PROXY exists but not https proxy': function () {
+ this.stub(process, 'env', { HTTP_PROXY: 'http://someproxy' });
+ assert.equals(http.proxy(), 'http://someproxy');
+ },
+ 'should return https proxy when url is not specified and HTTPS PROXY exists but not http proxy': function () {
+ this.stub(process, 'env', { HTTPS_PROXY: 'https://someproxy' });
+ assert.equals(http.proxy(), 'https://someproxy');
+ },
'should return undefined when url is not specified and no proxy environment variable exists': function () {
this.stub(process, 'env', {});
assert.equals(http.proxy(), undefined);

0 comments on commit 9ae0c4b

Please sign in to comment.