Repair missing commit(s)

This commit is contained in:
ciaranj
2014-12-18 20:12:24 +00:00
parent 9e27f4c128
commit a4b96af335
4 changed files with 76 additions and 17 deletions

View File

@ -60,6 +60,7 @@ exports.OAuth2.prototype._chooseHttpLibrary= function( parsedUrl ) {
exports.OAuth2.prototype._request= function(method, url, headers, post_body, access_token, callback) {
var creds = crypto.createCredentials({ });
var parsedUrl= URL.parse( url, true );
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) {
parsedUrl.port= 443;
@ -83,7 +84,16 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
realHeaders['User-Agent'] = 'Node-oauth';
}
realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
if( post_body ) {
if ( Buffer.isBuffer(post_body) ) {
realHeaders["Content-Length"]= post_body.length;
} else {
realHeaders["Content-Length"]= Buffer.byteLength(post_body);
}
} else {
realHeaders["Content-length"]= 0;
}
if( access_token && !('Authorization' in realHeaders)) {
if( ! parsedUrl.query ) parsedUrl.query= {};
parsedUrl.query[this._accessTokenName]= access_token;
@ -193,10 +203,12 @@ exports.OAuth2.prototype.getProtectedResource= function(url, access_token, callb
}
exports.OAuth2.prototype.get= function(url, access_token, callback) {
var headers= {};
if( this._useAuthorizationHeaderForGET ) {
headers= {'Authorization': this.buildAuthHeader(access_token) }
var headers= {'Authorization': this.buildAuthHeader(access_token) }
access_token= null;
}
else {
headers= {};
}
this._request("GET", url, headers, "", access_token, callback );
}