Skip to content

How identify which http client library made a request #42

Open
@kavanagh

Description

@kavanagh

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 })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions