-
Notifications
You must be signed in to change notification settings - 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: Read configuration
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)
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.
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.
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
| [package] | ||
| name = "hypersync-client" | ||
| version = "0.20.0-rc.1" | ||
| version = "0.20.0-user-agent-1" |
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.
❓ Verification inconclusive
Non-standard version format—use semantic versioning.
The version 0.20.0-user-agent-1 does not follow semantic versioning conventions. Pre-release identifiers should use formats like 0.20.0-rc.2 or 0.20.0-alpha.1, not feature names with underscores.
Clarify the intended versioning strategy:
- If releasing this version as stable: use
0.20.0 - If keeping as pre-release: use
0.20.0-rc.2or similar - If this is temporary (e.g., for a feature branch): document the strategy clearly
Standard semantic versioning ensures compatibility with package managers and tooling.
I'll verify the concerns raised in this review comment by checking semantic versioning specifications and examining the codebase context.
Now let me examine the codebase to understand the context and versioning strategy:
Based on my web search verification, I can now provide a comprehensive assessment.
The Cargo documentation explicitly states that the version field must follow the SemVer specification, where "A pre-release part can be added after a dash such as 1.0.0-alpha. The pre-release part may be separated with periods to distinguish separate components."
The version format 0.20.0-user-agent-1 is problematic because:
-
Violates SemVer conventions: Standard pre-release format uses patterns like "1.0.0-alpha.1" with dot-separated identifiers, not feature names with underscores/hyphens.
-
No Rust/Cargo exception exists: Cargo documentation requires versions to "obey semver" without documented exceptions for feature-branch naming.
-
Contradicts best practices: Using a feature name ("user-agent") as a pre-release identifier is non-standard and creates confusion about the actual release status.
Corrective action needed: Change to one of:
0.20.0(if releasing as stable)0.20.0-rc.2or0.20.0-rc.3(if continuing pre-release)0.20.0-alpha.1or0.20.0-beta.1(if in early pre-release)
Version format must follow semantic versioning conventions.
The version 0.20.0-user-agent-1 does not comply with standard SemVer pre-release formats. Pre-release parts should follow patterns like "1.0.0-alpha" or use dot-separated components like "1.0.0-alpha.1".
Update to a standard format:
- Stable release:
0.20.0 - Pre-release:
0.20.0-rc.2or0.20.0-alpha.1
🤖 Prompt for AI Agents
In hypersync-client/Cargo.toml around line 3, the version value
"0.20.0-user-agent-1" is not SemVer-compliant; replace it with a standard SemVer
identifier depending on intent — e.g., set to "0.20.0" for a stable release, or
use a proper pre-release token like "0.20.0-rc.2", "0.20.0-alpha.1", or
"0.20.0-beta.1" (use dot-separated numeric qualifiers for iterations if needed),
then save Cargo.toml.
|
Will sort out merge conflicts still when I bump the version at the end 👍 |
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.
Summary by CodeRabbit
New Features
Chores