diff --git a/lib/oauth2.js b/lib/oauth2.js index 94ed662c..08a2f53b 100644 --- a/lib/oauth2.js +++ b/lib/oauth2.js @@ -108,6 +108,13 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc headers: realHeaders }; + var proxyServer = process.env['https_proxy'] || process.env['HTTPS_PROXY']; + if (proxyServer) { + var HttpsProxyAgent = require('https-proxy-agent'); + var httpsProxyAgent = new HttpsProxyAgent(proxyServer); + options.agent = httpsProxyAgent; + } + this._executeRequest( http_library, options, post_body, callback ); } diff --git a/package.json b/package.json index 1a555333..2b0f40d4 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ , "main" : "index.js" , "author" : "Ciaran Jessup " , "repository" : { "type":"git", "url":"http://github.com/ciaranj/node-oauth.git" } +, "dependencies": { + "https-proxy-agent": "^1.0.0" + } , "devDependencies": { "vows": "0.5.x" } diff --git a/tests/oauth2tests.js b/tests/oauth2tests.js index 134f85bc..57a8ea44 100644 --- a/tests/oauth2tests.js +++ b/tests/oauth2tests.js @@ -286,5 +286,19 @@ vows.describe('OAuth2').addBatch({ oa.get("", {}); } } + }, + 'When the user has an https_proxy environment variable set': { + topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined, + undefined), + 'When calling get': { + 'we should see the http proxy agent in options passed to http-library' : function(oa) { + process.env.https_proxy = "http://proxy-server"; + oa._executeRequest= function( http_library, options, callback ) { + assert.isNotNull(options.agent); + }; + oa.get("", {}); + delete process.env.https_proxy; + } + } } }).export(module);