Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allows custom headers in http requests #33

Closed
wants to merge 2 commits into from

5 participants

@Qard

I changed the http request functions to allow an extra headers object before the final callback. I added a little hack in the _performSecureRequest() function to prevent this from breaking compatibility.

@ciaranj
Owner

Is 75a0073 actually required ? Presumably if I pull 337c2fb then the x-li-format is provided externally in your code?

@Qard

It's been awhile...I don't even remember what most of that stuff did. haha.

@eldavido

Is this dead? I'd also like the ability to pass custom request headers on HTTP GET requests. I can add it, with your guys' blessing.

@ciaranj
Owner

this commit seems to be, there are other outstanding issues offerring the same feature.

@eldavido

Which? I want this badly enough that I'll collaborate/lead getting it in.

@amwhaley

I really need the ability to add custom headers also. Is this thread still active? has there been any progress on this? I will help add this functionality also, if needed.

@ciaranj
Owner

You can provide static headers as the last argument to the OAuth(...) constructor if that helps ?

@akwintx

Yes, that will solve my current issue. Thanks!

@ciaranj
Owner

I'm assuming (unless) otherwise told this is no longer an issue.

@ciaranj ciaranj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 7, 2011
  1. @Qard
  2. @Qard

    Allow custom headers

    Qard authored
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 15 deletions.
  1. +21 −15 lib/oauth.js
View
36 lib/oauth.js
@@ -252,8 +252,14 @@ exports.OAuth.prototype._prepareParameters= function( oauth_token, oauth_token_s
return orderedParameters;
}
-exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback ) {
+exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, headers, callback ) {
var orderedParameters= this._prepareParameters(oauth_token, oauth_token_secret, method, url, extra_params);
+
+ // Hack for custom headers whithout breaking compatibility.
+ if (typeof headers == 'function') {
+ callback = headers;
+ delete headers;
+ }
if( !post_content_type ) {
post_content_type= "application/x-www-form-urlencoded";
@@ -262,7 +268,7 @@ 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 headers= {};
+ var headers= headers || {};
headers["Authorization"]= this._buildAuthorizationHeaders(orderedParameters);
headers["Host"] = parsedUrl.host
@@ -333,7 +339,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
return;
}
-exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_secret, oauth_verifier, callback) {
+exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_secret, oauth_verifier, callback) {
var extraParams= {};
if( typeof oauth_verifier == "function" ) {
callback= oauth_verifier;
@@ -355,19 +361,19 @@ exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_s
}
// Deprecated
-exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
- this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", null, callback );
+exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, headers, callback) {
+ this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", null, headers, callback );
}
-exports.OAuth.prototype.delete= function(url, oauth_token, oauth_token_secret, callback) {
- return this._performSecureRequest( oauth_token, oauth_token_secret, "DELETE", url, null, "", null, callback );
+exports.OAuth.prototype.delete= function(url, oauth_token, oauth_token_secret, headers, callback) {
+ return this._performSecureRequest( oauth_token, oauth_token_secret, "DELETE", url, null, "", null, headers, callback );
}
-exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, callback) {
- return this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", null, callback );
+exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, headers, callback) {
+ return this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", null, headers, callback );
}
-exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
+exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, headers, callback) {
var extra_params= null;
if( typeof post_content_type == "function" ) {
callback= post_content_type;
@@ -378,16 +384,16 @@ exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_tok
extra_params= post_body;
post_body= null;
}
- return this._performSecureRequest( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback );
+ return this._performSecureRequest( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, headers, callback );
}
-exports.OAuth.prototype.put= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
- return this._putOrPost("PUT", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
+exports.OAuth.prototype.put= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, headers, callback) {
+ return this._putOrPost("PUT", url, oauth_token, oauth_token_secret, post_body, post_content_type, headers, callback);
}
-exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
- return this._putOrPost("POST", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
+exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, headers, callback) {
+ return this._putOrPost("POST", url, oauth_token, oauth_token_secret, post_body, post_content_type, headers, callback);
}
exports.OAuth.prototype.getOAuthRequestToken= function(extraParams, callback) {
Something went wrong with that request. Please try again.