-
Notifications
You must be signed in to change notification settings - Fork 6
User agent #82
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
base: main
Are you sure you want to change the base?
User agent #82
Conversation
WalkthroughAdds a configurable HTTP user-agent to the client API: introduces Changes
Sequence Diagram(s)sequenceDiagram
actor Caller
participant ClientAPI as Client API
participant Internal as new_internal
participant Reqwest as reqwest::ClientBuilder
rect rgba(230,240,255,0.5)
Caller->>ClientAPI: Client::new(cfg)
note right of ClientAPI: Delegates with default UA\n"hscr/<version>"
ClientAPI->>Internal: new_internal(cfg, default_ua)
end
alt Custom user-agent
Caller->>ClientAPI: Client::new_with_agent(cfg, ua)
ClientAPI->>Internal: new_internal(cfg, ua)
end
Internal->>Reqwest: ClientBuilder::new()
Internal->>Reqwest: .user_agent(ua)
Reqwest-->>Internal: built Client
Internal-->>Caller: Client { http_client, ... }
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
hypersync-client/src/lib.rs (1)
79-84: Consider propagating the build error instead of unwrapping.With the new custom user agent feature, invalid user agent strings (containing characters not allowed in HTTP headers) could now cause a panic at line 84. Since
Client::newalready returnsResult<Self>, consider propagating the error for more graceful handling.Apply this diff to handle the error:
let http_client = reqwest::Client::builder() .no_gzip() .timeout(Duration::from_millis(timeout.get())) .user_agent(user_agent) .build() - .unwrap(); + .context("build http client")?;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
hypersync-client/src/config.rs(1 hunks)hypersync-client/src/lib.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
hypersync-client/src/lib.rs (1)
hypersync-client/src/config.rs (1)
user_agent(37-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: lint
- GitHub Check: test_release
- GitHub Check: test_dev
🔇 Additional comments (3)
hypersync-client/src/config.rs (2)
24-27: LGTM! Good encapsulation and serde configuration.The private field with
skip_serializing_ifis appropriate for optional configuration. The crate-private accessor provides controlled access while keeping the field encapsulated.
29-40: LGTM! Idiomatic builder pattern and accessor.The implementation follows Rust best practices:
- Builder-style setter with
impl Into<String>for flexibility- Crate-private accessor returns borrowed
&strto avoid allocations- Clear documentation about intended use for language bindings
hypersync-client/src/lib.rs (1)
73-77: LGTM! Clear default user agent with helpful comment.The fallback logic is well-implemented with a sensible default format that includes the library version. The comment explaining the "hscr" abbreviation is helpful.
hypersync-client/src/config.rs
Outdated
| /// Custom user agent string for HTTP requests. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| #[doc(hidden)] | ||
| pub user_agent: Option<String>, |
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.
hidden from documentation, making it "somewhat hidden"
I tried making it not public, but that wasn't really possible due to the structure of how you create the client.
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.
But it'll allow me to override it for the typescript/python and hyperindex. Will still test that out.
I should make an rc release.
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.
I don't really understand...
Do you want to be able to set this externally? Like from the nodejs client for eg?
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.
I think if it's not part of public cfg, rather add it as a parameter on the Client. So for eg, have an internal function like "new_internal" which takes the cfg and the user agent.
Then make "new" call this fn with the defaulted user agent. And have another fn called "new_with_agent" which passes in a custom agent.
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.
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.
Drafting up an alternative, but there will still be an option exposed to users to edit the user_agent one way or another...
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
hypersync-client/Cargo.toml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Publish to crates.io
- GitHub Check: lint
- GitHub Check: test_release
- GitHub Check: test_dev
|
Will sort out merge conflicts still when I bump the version at the end 👍 |
JonoPrest
left a comment
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.
Can you rebase onto main and add it as an rc.3 rather than your own side release?
Also have a slight opinion on keeping user agent out of the Config struct if its not really meant to be public.
It was challenging making it internal, but also easy to modify for the python/node and hyperindex clients. |
hypersync-client/src/config.rs
Outdated
| pub retry_ceiling_ms: Option<u64>, | ||
| /// Custom user agent string for HTTP requests. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| #[doc(hidden)] |
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.
@JonoPrest - this at least hides this from any generated docs.
…ional client initialization for this



Summary by CodeRabbit
New Features
Chores