Merge pull request #140 from AndrewMartens/master
Set default User-Agent if not otherwise specified in customHeaders
This commit is contained in:
commit
4d8bf8ba5f
@ -74,6 +74,10 @@ exports.OAuth2.prototype._request= function(method, url, headers, post_body, acc
|
|||||||
}
|
}
|
||||||
realHeaders['Host']= parsedUrl.host;
|
realHeaders['Host']= parsedUrl.host;
|
||||||
|
|
||||||
|
if (!realHeaders['User-Agent']) {
|
||||||
|
realHeaders['User-Agent'] = 'Node-oauth';
|
||||||
|
}
|
||||||
|
|
||||||
realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
|
realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
|
||||||
if( access_token && !('Authorization' in realHeaders)) {
|
if( access_token && !('Authorization' in realHeaders)) {
|
||||||
if( ! parsedUrl.query ) parsedUrl.query= {};
|
if( ! parsedUrl.query ) parsedUrl.query= {};
|
||||||
|
@ -133,5 +133,29 @@ vows.describe('OAuth2').addBatch({
|
|||||||
oa.get("", {});
|
oa.get("", {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'When the user passes in the User-Agent in customHeaders': {
|
||||||
|
topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,
|
||||||
|
{ 'User-Agent': '123Agent' }),
|
||||||
|
'When calling get': {
|
||||||
|
'we should see the User-Agent mixed into headers property in options passed to http-library' : function(oa) {
|
||||||
|
oa._executeRequest= function( http_library, options, callback ) {
|
||||||
|
assert.equal(options.headers["User-Agent"], "123Agent");
|
||||||
|
};
|
||||||
|
oa.get("", {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'When the user does not pass in a User-Agent in customHeaders': {
|
||||||
|
topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,
|
||||||
|
undefined),
|
||||||
|
'When calling get': {
|
||||||
|
'we should see the default User-Agent mixed into headers property in options passed to http-library' : function(oa) {
|
||||||
|
oa._executeRequest= function( http_library, options, callback ) {
|
||||||
|
assert.equal(options.headers["User-Agent"], "Node-oauth");
|
||||||
|
};
|
||||||
|
oa.get("", {});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user