From 24c91e02b9640647ac8ceb53ec575b6d6e948eff Mon Sep 17 00:00:00 2001 From: ciaranj Date: Sat, 14 Aug 2010 19:21:12 +0100 Subject: [PATCH] Add support for specifying whatever static HTTP headers one wishes with the OAuth requests --- lib/oauth.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/oauth.js b/lib/oauth.js index 49a1fa4..1d395fd 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -4,7 +4,7 @@ var crypto= require('crypto'), URL= require('url'), querystring= require('querystring'); -exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize) { +exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders) { this._requestUrl= requestUrl; this._accessUrl= accessUrl; this._consumerKey= consumerKey; @@ -21,6 +21,9 @@ exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, vers throw new Error("Un-supported signature method: " + signatureMethod ) this._signatureMethod= signatureMethod; this._nonceSize= nonceSize || 32; + this._headers= customHeaders || {"Accept" : "*/*", + "Connection" : "close", + "User-Agent" : "Node authentication"} }; exports.OAuth.prototype._getTimestamp= function() { @@ -207,9 +210,11 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke headers["Authorization"]= authHeader; headers["Host"] = parsedUrl.host - headers["Accept"]= "*/*" - headers["Connection"]= "close" - headers["User-Agent"]= "Express authentication" + + for( var key in this._headers ) { + headers[key]= this._headers[key]; + } + headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii headers["Content-Type"]= post_content_type;