Skip to content

Conversation

@JasoonS
Copy link
Collaborator

@JasoonS JasoonS commented Oct 27, 2025

Summary by CodeRabbit

  • New Features

    • Clients can set a custom User-Agent for HTTP requests; the default User-Agent remains unchanged for users who don't configure it.
  • Chores

    • Package version bumped to 0.20.0-rc.5.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Walkthrough

Adds a configurable HTTP user-agent to the client API: introduces Client::new_with_agent(cfg, user_agent) and an internal new_internal(cfg, user_agent) that set the reqwest client's user-agent; Client::new(cfg) delegates to the internal constructor using default "hscr/<version>". Bumps crate version to 0.20.0-rc.5.

Changes

Cohort / File(s) Summary
Client API & constructors
hypersync-client/src/lib.rs
Adds pub fn new_with_agent(cfg, user_agent: impl Into<String>) -> Result<Self> and an internal new_internal(cfg, user_agent); refactors new(cfg) to call new_internal and sets the reqwest client's .user_agent(...) (default "hscr/<version>" or provided agent).
Manifest version bump
hypersync-client/Cargo.toml
Updates package.version from 0.20.0-rc.3 to 0.20.0-rc.5.

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, ... }
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check that user_agent is applied to the reqwest client in all construction paths.
  • Verify the default "hscr/<version>" is correctly derived (build-time or cargo env).
  • Confirm visibility and docs for the new public method.

Poem

A rabbit taps the keyboard light,
"Set headers true — both day and night."
New agent hops into the stream,
Default or custom, pick your theme.
Version raised, the package sings,
Soft paws push new networking wings.

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 title 'User agent' directly corresponds to the main change in the PR, which adds public API for creating a client with a custom user-agent via new_with_agent() method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 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 123ecc5 and f435eb4.

📒 Files selected for processing (1)
  • hypersync-client/Cargo.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hypersync-client/Cargo.toml
⏰ 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: Publish to crates.io
  • GitHub Check: test_release
  • GitHub Check: test_dev

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
Collaborator 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
Collaborator 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.

Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw these messages now, to do that we'll need to make another struct.

With this it hides it from any generated docs, and LSP:
image
image

Here for example without the config: Screenshot from 2025-11-07 15-55-19
I

Copy link
Collaborator Author

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...

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

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

📒 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

@JasoonS JasoonS requested a review from JonoPrest October 29, 2025 15:16
@JasoonS
Copy link
Collaborator Author

JasoonS commented Oct 29, 2025

Will sort out merge conflicts still when I bump the version at the end 👍

Copy link
Collaborator

@JonoPrest JonoPrest left a 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.

@JasoonS
Copy link
Collaborator Author

JasoonS commented Nov 7, 2025

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.

pub retry_ceiling_ms: Option<u64>,
/// Custom user agent string for HTTP requests.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[doc(hidden)]
Copy link
Collaborator Author

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.

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.

3 participants