mirror of
https://github.com/HackPlan/google-auth-library-nodejs.git
synced 2026-04-28 11:46:35 +08:00
Fix User-Agent header
Prevent User-Agent header from growing with each request. Fixes #83
This commit is contained in:
@@ -39,8 +39,11 @@ DefaultTransporter.prototype.USER_AGENT =
|
||||
DefaultTransporter.prototype.configure = function(opts) {
|
||||
// set transporter user agent
|
||||
opts.headers = opts.headers || {};
|
||||
opts.headers['User-Agent'] = opts.headers['User-Agent'] ?
|
||||
opts.headers['User-Agent'] + ' ' + this.USER_AGENT : this.USER_AGENT;
|
||||
if (!opts.headers['User-Agent']) {
|
||||
opts.headers['User-Agent'] = this.USER_AGENT;
|
||||
} else if (opts.headers['User-Agent'].indexOf(this.USER_AGENT) === -1) {
|
||||
opts.headers['User-Agent'] = opts.headers['User-Agent'] + ' ' + this.USER_AGENT;
|
||||
}
|
||||
return opts;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
var assert = require('assert');
|
||||
var DefaultTransporter = require('../lib/transporters');
|
||||
var nock = require('nock');
|
||||
var version = require('../package.json').version;
|
||||
|
||||
nock.disableNetConnect();
|
||||
|
||||
@@ -42,6 +43,15 @@ describe('Transporters', function() {
|
||||
assert(re.test(opts.headers['User-Agent']));
|
||||
});
|
||||
|
||||
it('should not append default client user agent to the existing user ' +
|
||||
'agent more than once', function() {
|
||||
var applicationName = 'MyTestApplication-1.0 google-api-nodejs-client/' + version;
|
||||
var opts = transporter.configure({
|
||||
headers: { 'User-Agent': applicationName }
|
||||
});
|
||||
assert.equal(opts.headers['User-Agent'], applicationName);
|
||||
});
|
||||
|
||||
it('should create a single error from multiple response errors', function(done) {
|
||||
var firstError = {
|
||||
message: 'Error 1'
|
||||
|
||||
Reference in New Issue
Block a user