fix: remove user-agent override
#1271
Thanks for the PR. If you can update it to only make the change to not set the header if the user already provided one, we can merge it.
So, are you saying that the logic for generating the grpc-js-* string should be removed, and we should just pass the header instead?
So, are you saying that the logic for generating the grpc-js-* string should be removed
Yes.
and we should just pass the header instead?
Currently, we're always setting the User-Agent header, regardless of whether the user has already provided one. For example:
await client.say(
{ sentence: "hello" },
{
headers: {
"User-Agent": "foo",
}
}
);
The User-Agent: foo is overwritten.
Following https://github.com/connectrpc/connect-es/issues/1271#issuecomment-2411048990, we should change the behavior, and not overwrite the user-provided value, but continue to set our value if the user didn't provide one.
The important part is that we do it consistently, not just in the gRPC transport, but also for gRPC-Web and the Connect transport.
Adding a transport option for a default user-agent is a nice idea, but it raises the question whether we shouldn't have an option for default headers instead. For now, the best action is to not add this option, and consider this change separately.
Currently, we're always setting the
User-Agentheader, regardless of whether the user has already provided one. For example:
The problem is:
-
Passing headers would require changing the code throughout the entire codebase. In my previous project, I had thousands of gRPC requests, and modifying all of them would be difficult.
-
Using interceptors introduces unnecessary overhead, especially when using AsyncLocalStorage.
Adding a transport option for a default user-agent is a nice idea, but it raises the question whether we shouldn't have an option for default headers instead. For now, the best action is to not add this option, and consider this change separately.
Yes, but, for example, I can pass headers directly:
server := grpc.Dial(grpc_server, WithUserAgent("user-agent",))
To fix #1271, we can allow to pass a custom user agent via CallOptions.headers, which is a reasonable incremental change.
We can discuss other features separately.
@timostamm
@timostamm Greetings! Will you be able to watch it?