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

Default User-Agent header is overwritten by DefaultTransporter #1890

Closed
7 tasks done
josephdpurcell opened this issue Nov 1, 2024 · 2 comments
Closed
7 tasks done

Comments

@josephdpurcell
Copy link

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

I could not find this package in the apis explorer.

Screenshot 2024-11-01 at 12 54 01

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/josephdpurcell/b434efc4870e4e7ba8387f9f7b98fd47

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Download the test-user-agent.ts file into a directory that has google-auth-library NPM package installed
  2. Run ts-node test-user-agent.ts
  3. Notice that the User-Agent sent in the request is google-api-nodejs-client/9.14.2

A clear and concise description of what the bug is, and what you expected to happen.

If you set the default request header User-Agent to foo/1 and you do not overwrite the User-Agent header in the per-request configuration then I would expect foo/1 to get sent out. When I say "per-request configuration" I mean like this:

idTokenClient.request({
  headers: { 'User-Agent': 'bar/1' },
});

Currently, what happens is this order of precedence:

  1. The per-request User-Agent gets appended with google-api-nodejs-client/9.14.2. Example, if you pass bar/1 the User-Agent sent is bar/1 google-api-nodejs-client/9.14.2.
  2. If you do not set per-request User-Agent then the User-Agent sent is google-api-nodejs-client/9.14.2.
  3. If you have a default User-Agent set it will still be google-api-nodejs-client/9.14.2.

I expect the order of precedence to be:

  1. No change. It's OK for the per-request User-Agent to be appended.
  2. If you do not set per-request User-Agent then the default User-Agent should be used. It's OK for the default User-Agent to be appended.
  3. If neither a per-request User-Agent nor a default User-Agent is set then the User-Agent is google-api-nodejs-client/9.14.2.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

I do not want to have to pass the User-Agent on every request call. I want to set the User-Agent as a default request header and that be respected by the library.

Copy link

github-actions bot commented Nov 1, 2024

Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node)

@github-actions github-actions bot closed this as completed Nov 1, 2024
@josephdpurcell
Copy link
Author

josephdpurcell commented Nov 1, 2024

Not sure why this was closed. I linked to a public gist, which the instructions say is acceptable.

#1489 (comment) is a workaround that can be used. I have a variation here that uses the default https://gist.github.com/josephdpurcell/b434efc4870e4e7ba8387f9f7b98fd47#file-workaround-ts.

I suppose at least this issue is documented for the next person.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant