Skip to content

Conversation

@JasoonS
Copy link
Contributor

@JasoonS JasoonS commented Oct 27, 2025

Summary by CodeRabbit

  • New Features
    • User-Agent header customization: you can set a custom User-Agent string for each client instance, or rely on the default identifier (used automatically). This lets you label and track requests from different clients for monitoring, debugging, or integration with external services.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

Adds an optional user_agent field to ClientConfig with a chainable setter and uses the configured or default user-agent string when building the internal reqwest::Client.

Changes

Cohort / File(s) Summary
User agent configuration
hypersync-client/src/config.rs
Adds user_agent: Option<String> to ClientConfig; adds with_user_agent(mut self, user_agent: impl Into<String>) -> Self setter and a crate-private user_agent() accessor; serde annotations applied.
HTTP client initialization
hypersync-client/src/lib.rs
Constructs a user_agent value from config or falls back to "hscr/<version>" and passes it to reqwest::Client via .user_agent(user_agent) during Client::new.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check serde annotations and visibility of the accessor.
  • Verify default UA formatting and correct passing into reqwest builder.

Poem

🐰 I hopped into config, quiet and spry,
A little string for the web to reply.
Chain me, set me, or leave me be—
I’ll introduce your client with gentle glee. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "User agent" directly relates to the main change in the changeset, which adds user agent configuration support to the hypersync client. Specifically, it adds a new user_agent field to ClientConfig with a setter method, and implements logic in Client::new to use either a configured user agent or a default one. The title is clear and specific enough that a teammate scanning the repository history would immediately understand this PR introduces user agent functionality, without being vague or misleading.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch user-agent

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d63e6a and 06586aa.

📒 Files selected for processing (2)
  • hypersync-client/src/config.rs (1 hunks)
  • hypersync-client/src/lib.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • hypersync-client/src/lib.rs
  • hypersync-client/src/config.rs
⏰ 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: test_release
  • GitHub Check: test_dev
  • GitHub Check: lint

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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::new already returns Result<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

📥 Commits

Reviewing files that changed from the base of the PR and between f91c16a and 6d63e6a.

📒 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_if is 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 &str to 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>,
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant