Skip to content

Commit

Permalink
fix: don't append x-goog-api-client multiple times (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 22, 2019
1 parent 6730698 commit a46b271
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/transporters.ts
Expand Up @@ -70,11 +70,14 @@ export class DefaultTransporter {
}
// track google-auth-library-nodejs version:
const authVersion = `auth/${pkg.version}`;
if (opts.headers['x-goog-api-client']) {
if (
opts.headers['x-goog-api-client'] &&
!opts.headers['x-goog-api-client'].includes(authVersion)
) {
opts.headers[
'x-goog-api-client'
] = `${opts.headers['x-goog-api-client']} ${authVersion}`;
} else {
} else if (!opts.headers['x-goog-api-client']) {
const nodeVersion = process.version.replace(/^v/, '');
opts.headers[
'x-goog-api-client'
Expand Down
18 changes: 17 additions & 1 deletion test/test.transporters.ts
Expand Up @@ -71,12 +71,28 @@ it('should append to x-goog-api-client header if it exists', () => {
headers: {'x-goog-api-client': 'gdcl/1.0.0'},
url: '',
});
console.info(opts.headers);
assert(
/^gdcl\/[.-\w$]+ auth\/[.-\w$]+$/.test(opts.headers!['x-goog-api-client'])
);
});

// see: https://github.com/googleapis/google-auth-library-nodejs/issues/819
it('should not append x-goog-api-client header multiple times', () => {
const opts = {
headers: {'x-goog-api-client': 'gdcl/1.0.0'},
url: '',
};
let configuredOpts = transporter.configure(opts);
console.info(configuredOpts);
configuredOpts = transporter.configure(opts);
console.info(configuredOpts);
assert(
/^gdcl\/[.-\w$]+ auth\/[.-\w$]+$/.test(
configuredOpts.headers!['x-goog-api-client']
)
);
});

it('should create a single error from multiple response errors', done => {
const firstError = {message: 'Error 1'};
const secondError = {message: 'Error 2'};
Expand Down

0 comments on commit a46b271

Please sign in to comment.