Allow passing binary data to PUT or POST as a Buffer
Allow the post_body argument to a PUT or POST to be a Buffer. This will pass the data directly to the request in binary form. Closes #144.
This commit is contained in:
parent
3fc9c63a06
commit
509cad25ef
13
lib/oauth.js
13
lib/oauth.js
@ -336,7 +336,16 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke
|
|||||||
.replace(/\*/g, "%2A");
|
.replace(/\*/g, "%2A");
|
||||||
}
|
}
|
||||||
|
|
||||||
headers["Content-length"]= post_body ? Buffer.byteLength(post_body) : 0;
|
if( post_body ) {
|
||||||
|
if ( Buffer.isBuffer(post_body) ) {
|
||||||
|
headers["Content-length"]= post_body.length;
|
||||||
|
} else {
|
||||||
|
headers["Content-length"]= Buffer.byteLength(post_body);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
headers["Content-length"]= 0;
|
||||||
|
}
|
||||||
|
|
||||||
headers["Content-Type"]= post_content_type;
|
headers["Content-Type"]= post_content_type;
|
||||||
|
|
||||||
var path;
|
var path;
|
||||||
@ -468,7 +477,7 @@ exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_tok
|
|||||||
callback= post_content_type;
|
callback= post_content_type;
|
||||||
post_content_type= null;
|
post_content_type= null;
|
||||||
}
|
}
|
||||||
if( typeof post_body != "string" ) {
|
if ( typeof post_body != "string" && !Buffer.isBuffer(post_body) ) {
|
||||||
post_content_type= "application/x-www-form-urlencoded"
|
post_content_type= "application/x-www-form-urlencoded"
|
||||||
extra_params= post_body;
|
extra_params= post_body;
|
||||||
post_body= null;
|
post_body= null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user