diff --git a/lib/oauth2.js b/lib/oauth2.js index 77241c43..85c8bed2 100644 --- a/lib/oauth2.js +++ b/lib/oauth2.js @@ -78,8 +78,10 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc var realHeaders= {}; - for( var key in this._customHeaders ) { - realHeaders[key]= this._customHeaders[key]; + for (var key in this._customHeaders) { + if (key != "agentAddOptions") { + realHeaders[key] = this._customHeaders[key]; + } } if( headers ) { for(var key in headers) { @@ -117,6 +119,12 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc headers: realHeaders }; + if (this._customHeaders.agentAddOptions) { + for (var key in this._customHeaders.agentAddOptions) { + options[key] = this._customHeaders.agentAddOptions[key]; + } + } + this._executeRequest( http_library, options, post_body, callback ); } @@ -225,4 +233,4 @@ exports.OAuth2.prototype.get= function(url, access_token, callback) { headers= {}; } this._request("GET", url, headers, "", access_token, callback ); -} +} \ No newline at end of file diff --git a/tests/oauth2tests.js b/tests/oauth2tests.js index 8be23e35..a77455d7 100644 --- a/tests/oauth2tests.js +++ b/tests/oauth2tests.js @@ -300,5 +300,18 @@ vows.describe('OAuth2').addBatch({ }, {}, null, function() {}); } } + }, + 'When the user passes in the agent options in customHeaders': { + topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined, + { 'agentAddOptions' : { 'rejectUnauthorized': false } }), + 'When calling get': { + 'we should see the agent options mixed into options property passed to http-library' : function(oa) { + oa._executeRequest= function( http_library, options, callback ) { + assert.equal(options["rejectUnauthorized"], false); + assert.equal(options.headers["rejectUnauthorized"], undefined); + }; + oa.get("", {}); + } + } } }).export(module);