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

Allow user-provided User-Agent request header #1271

Closed
polRk opened this issue Oct 11, 2024 · 5 comments
Closed

Allow user-provided User-Agent request header #1271

polRk opened this issue Oct 11, 2024 · 5 comments

Comments

@polRk
Copy link

polRk commented Oct 11, 2024

result.set(headerUserAgent, "CONNECT_ES_USER_AGENT");

User header must have priority and override useragent header defined buy library

@timostamm
Copy link
Member

The user-agent set by connect-es is important to use because it helps users and us to diagnose issues.

Can you provide some details on why it is important to you to override the header?

@polRk
Copy link
Author

polRk commented Oct 12, 2024

The user-agent set by connect-es is important to use because it helps users and us to diagnose issues.

Can you provide some details on why it is important to you to override the header?

It is very important to add information not only about connect-es, but also about runtime and even about the product

@timostamm
Copy link
Member

Okay, it's reasonable to not set the User-Agent request header if the user already provided one via CallOptions.headers.

This applies to the Connect, gRPC, and gRPC-Web transports, but not to the ones from @connectrpc/connect-web, since we do not set the header there (#912).

Until this change is made, you can use an interceptor to set a custom user agent:

const transport = createConnectTransport({
  baseUrl: "https://demo.connectrpc.com",
  interceptors: [
    (next) => async (req) => {
      req.header.set("User-Agent", "FOO");
      return await next(req);
    }
  ]
});

@timostamm timostamm changed the title Override headers Allow user-provided User-Agent request header Oct 14, 2024
@polRk
Copy link
Author

polRk commented Oct 17, 2024

The problem is: Using interceptors introduces unnecessary overhead, especially when using AsyncLocalStorage.

@timostamm
Copy link
Member

Closed by #1272.

It would be convenient to have a transport-level option, but we try to keep the API lean. Interceptors (as suggested in #1271 (comment)), shouldn't have a perceivable impact on performance.

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

2 participants