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

feat(transport): add user-agent header to client requests. #457

Merged
merged 6 commits into from
Sep 23, 2020

Conversation

alce
Copy link
Collaborator

@alce alce commented Sep 18, 2020

This PR adds a user-agent header to client requests. The default value is tonic/x.x.x. The value can be configured through the Channel builder.

Endpoint::from_static("...").user_agent("Greeter 1.1")?.connect();

The value passed to the user_agent method will be prepended to the default, in this case the full value will be: Greeter 1.1 tonic/0.3.1.

The header is added by a new UserAgent layer in the client's service stack. While this is not the most straight forward implementation, it seemed to be the cleanest and safest one. It also aligns better with other client implementations (grpc-go clients, in particular).

Alternatives

  • Remove user-agent from the list of grpc reserved headers.
  • Do not filter out the user-agent header in tonic <-> http request conversions.
  • Sniff the request after passing it to the interceptor fn to see if user-agent was set, pluck it out and add it manually after mapping the request.
  • Move the optional header from the Endpoint to the client::Grpc struct and set the header after converting the request.
  • Don't set user-agent headers at all.

...and maybe others.

fixes #453

* Adds a default user-agent to tonic `Channel`.
* The user agent can be configured through the `Channel` builder.

fixes hyperium#453
Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one style nit, should we consider adding tests for this?

tonic/src/transport/channel/endpoint.rs Outdated Show resolved Hide resolved
@alce
Copy link
Collaborator Author

alce commented Sep 23, 2020

Sure, I'll add a test.

@alce
Copy link
Collaborator Author

alce commented Sep 23, 2020

ha, weird merging of imports, hang on...

@alce alce merged commit d4899df into hyperium:master Sep 23, 2020
@alertedsnake
Copy link

This is awesome, @alce - thanks for working on it!

@alce
Copy link
Collaborator Author

alce commented Sep 24, 2020

@alertedsnake thanks! And thank you for reporting the issue.

@alce alce deleted the user-agent branch September 24, 2020 15:13
@alertedsnake
Copy link

Just confirmed this is working perfectly in my real-world situation, so thanks again :)

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

Successfully merging this pull request may close these issues.

Support gRPC channel options
3 participants