Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't append x-goog-api-client multiple times #820

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/transporters.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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