Merge branch '0.4_compat_fixes'
Conflicts: lib/oauth.js
This commit is contained in:
43
lib/oauth.js
43
lib/oauth.js
@ -1,6 +1,7 @@
|
||||
var crypto= require('crypto'),
|
||||
sha1= require('./sha1'),
|
||||
http= require('http'),
|
||||
https= require('https'),
|
||||
URL= require('url'),
|
||||
querystring= require('querystring');
|
||||
|
||||
@ -193,8 +194,21 @@ exports.OAuth.prototype._getNonce= function(nonceSize) {
|
||||
return result.join('');
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._createClient= function( port, hostname, sslEnabled, credentials ) {
|
||||
return http.createClient(port, hostname, sslEnabled, credentials);
|
||||
exports.OAuth.prototype._createClient= function( port, hostname, method, path, headers, sslEnabled ) {
|
||||
var options = {
|
||||
host: hostname,
|
||||
port: port,
|
||||
path: path,
|
||||
method: method,
|
||||
headers: headers
|
||||
};
|
||||
var httpModel;
|
||||
if( sslEnabled ) {
|
||||
httpModel= https;
|
||||
} else {
|
||||
httpModel= http;
|
||||
}
|
||||
return httpModel.request(options);
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._prepareParameters= function( oauth_token, oauth_token_secret, method, url, extra_params ) {
|
||||
@ -248,14 +262,6 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
||||
if( parsedUrl.protocol == "http:" && !parsedUrl.port ) parsedUrl.port= 80;
|
||||
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) parsedUrl.port= 443;
|
||||
|
||||
var oauthProvider;
|
||||
if( parsedUrl.protocol == "https:" ) {
|
||||
oauthProvider= this._createClient(parsedUrl.port, parsedUrl.hostname, true, crypto.createCredentials({}));
|
||||
}
|
||||
else {
|
||||
oauthProvider= this._createClient(parsedUrl.port, parsedUrl.hostname);
|
||||
}
|
||||
|
||||
var headers= {};
|
||||
headers["Authorization"]= this._buildAuthorizationHeaders(orderedParameters);
|
||||
headers["Host"] = parsedUrl.host
|
||||
@ -285,16 +291,23 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
||||
if( parsedUrl.query ) path= parsedUrl.pathname + "?"+ parsedUrl.query ;
|
||||
else path= parsedUrl.pathname;
|
||||
|
||||
var request = oauthProvider.request(method, path , headers);
|
||||
var request;
|
||||
if( parsedUrl.protocol == "https:" ) {
|
||||
request= this._createClient(parsedUrl.port, parsedUrl.hostname, method, path, headers, true);
|
||||
}
|
||||
else {
|
||||
request= this._createClient(parsedUrl.port, parsedUrl.hostname, method, path, headers);
|
||||
}
|
||||
|
||||
if( callback ) {
|
||||
var data="";
|
||||
var self= this;
|
||||
request.addListener('response', function (response) {
|
||||
request.on('response', function (response) {
|
||||
response.setEncoding('utf8');
|
||||
response.addListener('data', function (chunk) {
|
||||
response.on('data', function (chunk) {
|
||||
data+=chunk;
|
||||
});
|
||||
response.addListener('end', function () {
|
||||
response.on('end', function () {
|
||||
if( response.statusCode != 200 ) {
|
||||
callback({ statusCode: response.statusCode, data: data });
|
||||
} else {
|
||||
@ -303,7 +316,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
||||
});
|
||||
});
|
||||
|
||||
request.socket.addListener("error",callback);
|
||||
request.on("error", callback);
|
||||
|
||||
if( (method == "POST" || method =="PUT") && post_body != null && post_body != "" ) {
|
||||
request.write(post_body);
|
||||
|
Reference in New Issue
Block a user