Skip to content

Commit

Permalink
fix: remove auth lib version from x-goog-api-client header (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed May 31, 2023
1 parent 3563c16 commit ce6013c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/transporters.ts
Expand Up @@ -68,19 +68,9 @@ export class DefaultTransporter implements Transporter {
] = `${uaValue} ${DefaultTransporter.USER_AGENT}`;
}
// track google-auth-library-nodejs version:
const authVersion = `auth/${pkg.version}`;
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 if (!opts.headers['x-goog-api-client']) {
if (!opts.headers['x-goog-api-client']) {
const nodeVersion = process.version.replace(/^v/, '');
opts.headers[
'x-goog-api-client'
] = `gl-node/${nodeVersion} ${authVersion}`;
opts.headers['x-goog-api-client'] = `gl-node/${nodeVersion}`;
}
}
return opts;
Expand Down
14 changes: 3 additions & 11 deletions test/test.transporters.ts
Expand Up @@ -58,21 +58,15 @@ describe('transporters', () => {
const opts = transporter.configure({
url: '',
});
assert(
/^gl-node\/[.-\w$]+ auth\/[.-\w$]+$/.test(
opts.headers!['x-goog-api-client']
)
);
assert(/^gl-node\/[.-\w$]+$/.test(opts.headers!['x-goog-api-client']));
});

it('should append to x-goog-api-client header if it exists', () => {
const opts = transporter.configure({
headers: {'x-goog-api-client': 'gdcl/1.0.0'},
url: '',
});
assert(
/^gdcl\/[.-\w$]+ auth\/[.-\w$]+$/.test(opts.headers!['x-goog-api-client'])
);
assert(/^gdcl\/[.-\w$]+$/.test(opts.headers!['x-goog-api-client']));
});

// see: https://github.com/googleapis/google-auth-library-nodejs/issues/819
Expand All @@ -84,9 +78,7 @@ describe('transporters', () => {
let configuredOpts = transporter.configure(opts);
configuredOpts = transporter.configure(opts);
assert(
/^gdcl\/[.-\w$]+ auth\/[.-\w$]+$/.test(
configuredOpts.headers!['x-goog-api-client']
)
/^gdcl\/[.-\w$]+$/.test(configuredOpts.headers!['x-goog-api-client'])
);
});

Expand Down

0 comments on commit ce6013c

Please sign in to comment.