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

How identify which http client library made a request #42

Open
kavanagh opened this issue Dec 11, 2024 · 0 comments
Open

How identify which http client library made a request #42

kavanagh opened this issue Dec 11, 2024 · 0 comments

Comments

@kavanagh
Copy link
Member

We’re using this library in a package that expects a global fetch to be available, allowing the consuming application to choose between node’s native fetch, isomorphic fetch or other similar option.

What’s the right way to ensure accurate details about which fetch is in use when sending the user agent?

The following can be inaccurate because the node-fetch library may be installed but not actually be in use for the http request being sent.

buildUserAgent({ libraries: ['node-fetch'] });

Being able to identify which fetch is being used in combination with out library will allow us to have visibility (in logs) of how its being used and pin down bugs related to a specific fetch implementation.

Perhaps we want to have this kind of thing user agent string? Internally it provides more granular information, but could it sometimes leak the wrong info? IDK...

  • "FTSystem/myapp/1.2.3 (node-fetch/2.0.0; Node.js/22.3.0)" if node-fetch was used to make the request
  • "FTSystem/myapp/1.2.3 (Node.js/22.3.0; node:fetch)" if native fetch is used
  • "FTSystem/myapp/1.2.3 (Node.js/22.3.0; node:http)" if the native http client is used

Potential interface for our use case (allowing user-agent-node to detect the implementation:

buildUserAgent({ libraries: ['@financial-times/node-user-preferences-clients'], httpClient: fetch })
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