tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Have full control over the User-Agent

Open daladim opened this issue 3 years ago • 10 comments

Feature Request

Motivation

The User-Agent header is populated, by default, with tonic/x.y.z (x.y.z. being the current tonic version number)
There is a user_agent method to somehow customize this by adding a prefix to this tonic/x.y.z part.

Proposal

In some use cases, users could want to totally customize the user-agent. Not suffixing with tonic/x.y.z would probably be a good idea.

I'm not sure why this suffix has been made compulsory anyway (but maybe I'm missing something? Is this required by some spec? I feel that any server requiring to know the client version is probably poorly designed)

Thanks

daladim avatar Apr 11 '22 08:04 daladim

The endpoint code will be going away in future releases, so I am adverse to making changes like this right now. That said, you can always wrap your Client in a tower service and use https://docs.rs/tower-http/latest/tower_http/trait.ServiceBuilderExt.html#tymethod.override_request_header to set the user agent header with what you 'd like.

LucioFranco avatar Apr 11 '22 14:04 LucioFranco

@LucioFranco isnt tonic transport lower level than tower middleware? wont tonic just override the tower value?

stan-irl avatar May 15 '23 07:05 stan-irl

I just confirmed that behaviour with a test. the tonic transport overrides whatever value is set in the middleware layer

stan-irl avatar May 15 '23 10:05 stan-irl

Would you accept a PR adding a dont_set_tonic_version_in_user_agent (bikeshed pending) method on Channel to fix this issue?

roblabla avatar Apr 04 '24 11:04 roblabla