-
Couldn't load subscription status.
- Fork 5
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 an optional Changes
Sequence Diagram(s)sequenceDiagram
participant Config as ClientConfig
participant ClientInit as Client::new
participant Reqwest as reqwest::Client::builder
Note over Config,ClientInit: Configuration read
Config->>ClientInit: user_agent() -> Option<String>
alt user_agent present
ClientInit->>Reqwest: .user_agent(configured UA)
else no user_agent
ClientInit->>ClientInit: compose "hscr/<version>"
ClientInit->>Reqwest: .user_agent(default UA)
end
Reqwest-->>ClientInit: built reqwest 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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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.
| /// 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.
Summary by CodeRabbit