-
Notifications
You must be signed in to change notification settings - Fork 81
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 #1272
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
I understand the idea, but we do not want to make a breaking change to user agent strings. Please avoid unnecessary changes to whitespace (npx turbo run format
runs prettier).
So, are you saying that the logic for generating the grpc-js-* string should be removed, and we should just pass the header instead? |
376ead2
to
fe51366
Compare
Yes.
Currently, we're always setting the await client.say(
{ sentence: "hello" },
{
headers: {
"User-Agent": "foo",
}
}
); The Following #1271 (comment), 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. |
The problem is:
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 We can discuss other features separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
Can you apply the same change to the Connect and gRPC-Web transports for consistency? It would be very confusing if this only works with gRPC. The transports from @connectrpc/connect-web
don't set a user-agent, no need to update them.
@@ -34,7 +34,7 @@ describe("requestHeader", () => { | |||
"user-agent", | |||
]); | |||
expect(headers.get("Content-Type")).toBe("application/grpc+proto"); | |||
expect(headers.get("User-Agent")).toMatch(/^connect-es\/\d+\.\d+\.\d+/); | |||
expect(headers.get("User-Agent")).toMatch(/^connect-es\/.*/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not modify this test. It makes sure the default user agent doesn't regress.
@@ -48,6 +48,17 @@ describe("requestHeader", () => { | |||
expect(headers.get("Grpc-Timeout")).toBe("10m"); | |||
}); | |||
|
|||
it("should create request headers with userAgent", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test!
// See https://github.com/grpc/grpc/blob/c462bb8d485fc1434ecfae438823ca8d14cf3154/doc/PROTOCOL-HTTP2.md#user-agents | ||
result.set(headerUserAgent, "CONNECT_ES_USER_AGENT"); | ||
|
||
if (!result.has(headerUserAgent)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and simple 👍
@timostamm Greetings! Will you be able to watch it? |
Signed-off-by: Vladislav Polyakov <[email protected]>
Signed-off-by: Vladislav Polyakov <[email protected]>
Signed-off-by: Timo Stamm <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!
I was out of office last week. Let's get this merged.
Pushed 4862f94 to update the bundle size benchmarks.
#1271