feat(storage): support setting a custom user-agent on the client#4839
feat(storage): support setting a custom user-agent on the client#4839joshuatants merged 2 commits intogoogleapis:mainfrom
Conversation
|
I'm wondering if it's better to add |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4839 +/- ##
=======================================
Coverage 94.52% 94.52%
=======================================
Files 210 210
Lines 8304 8317 +13
=======================================
+ Hits 7849 7862 +13
Misses 455 455 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f9c2401 to
0e6887c
Compare
coryan
left a comment
There was a problem hiding this comment.
I'm wondering if it's better to add user_agent agent directly to storage::RequestOptions instead of to CommonOptions. WDYT?
You are probably right. Putting it in CommonOptions now forces us to think about how a per-client setting works.
When I was thinking about the feature request I was thinking about how in (say) secret manager I can say:
let client = SecretManagerService::builder().build().await?;
let get = client.get_secret().with_user_agent("foo/1.0").send().await?;And the goal was to do the analogous thing for Storage:
let client = Storage::builder().build().await?;
let reader = client.read_object("projects/_/buckets/my-bucket", "my-object")
.with_user_agent("foo/1.0") // ERROR, LET'S FIX THIS
.send().await?;This PR gives applications a different feature, they can do this now:
let client = Storage::builder()
.set_user_agent("foo/1.0") // NEW, COOL, BUT NOT WHAT ASKED.
.build().await?;
let reader = client.read_object("projects/_/buckets/my-bucket", "my-object")
.with_user_agent("bar/1.0") // STILL AN ERROR...
.send().await?;
To be clear: we will want the change in this PR too, someday, but it is not (I believe) what #3615 is asking.
In passing: the other changes in #3615 (host header, using reqwest::Client, library instrumentation for observability) are already done. You can mark that issue as fixed once the support for setting the user header is done.
60f12dd to
b17d1b6
Compare
coryan
left a comment
There was a problem hiding this comment.
Thanks. There are a couple of extra changes that look out of place. I trust you to revert them and then merge the code.
|
So the below should be possible with this change? ` let latest_builder: ReadObject = ` |
yes, that is the intent. |
| Expectation::matching(all_of![ | ||
| request::method_path("GET", "/storage/v1/b/test-bucket/o/test-object"), | ||
| request::headers(contains(("accept-encoding", "gzip"))), | ||
| request::headers(contains((USER_AGENT.as_str(), user_agent))), |
There was a problem hiding this comment.
@coryan I wanted to use USER_AGENT here without having to have the storage crate depend direct on reqwest. I thought it'd be safer to use the constant from reqwest, though this is very minor since user-agent is practically a universal string. If I do want to use the constant from reqwest, is there a better way than making it visible through gaxi?
There was a problem hiding this comment.
I would not export an extra name from google-cloud-gax-internal for a test like this. You can use http which also provides the constants and it is 1.0:
https://docs.rs/http/latest/http/header/constant.USER_AGENT.html
and since you are using .as_str() there is no type compatibility to worry about. And you have to use .as_str(), because this is going into httptest that does not use HeaderName for matching, just string slices.
I am not sure if those are "better", but the exporting the constant is not helping you that much anyway.
There was a problem hiding this comment.
Got it thanks. If I decide it's worth it I'll submit the change in a separate PR.
b17d1b6 to
7c28b62
Compare
|
And sorry I realise I amended my commit instead of creating a new one, thereby losing your comments from before... |
No worries. |
As requested in #3615