From 80f604f17c45596121aae564ee31b3f4fbe7ee6a Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Oct 2025 22:40:20 +0200 Subject: [PATCH 1/7] basic user-agent config --- hypersync-client/src/config.rs | 3 +++ hypersync-client/src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/hypersync-client/src/config.rs b/hypersync-client/src/config.rs index 0b1d8be..efd763f 100644 --- a/hypersync-client/src/config.rs +++ b/hypersync-client/src/config.rs @@ -24,6 +24,9 @@ pub struct ClientConfig { /// Query serialization format to use for HTTP requests. #[serde(default)] pub serialization_format: SerializationFormat, + /// Custom user agent string for HTTP requests. + #[serde(skip_serializing_if = "Option::is_none")] + pub user_agent: Option, } /// Determines query serialization format for HTTP requests. diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index b9c2bb5..e58de3c 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -73,9 +73,14 @@ impl Client { .http_req_timeout_millis .unwrap_or(NonZeroU64::new(30_000).unwrap()); + let user_agent = cfg + .user_agent + .unwrap_or_else(|| format!("hypersync-client-rust/{}", env!("CARGO_PKG_VERSION"))); + let http_client = reqwest::Client::builder() .no_gzip() .timeout(Duration::from_millis(timeout.get())) + .user_agent(user_agent) .build() .unwrap(); From 426be94e8ea52e4a18ab4caa4c08b5c90a49aca4 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Oct 2025 22:43:51 +0200 Subject: [PATCH 2/7] make the user_agent non public on the client config, use builder function --- hypersync-client/src/config.rs | 15 ++++++++++++++- hypersync-client/src/lib.rs | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hypersync-client/src/config.rs b/hypersync-client/src/config.rs index efd763f..d7020b1 100644 --- a/hypersync-client/src/config.rs +++ b/hypersync-client/src/config.rs @@ -26,7 +26,20 @@ pub struct ClientConfig { pub serialization_format: SerializationFormat, /// Custom user agent string for HTTP requests. #[serde(skip_serializing_if = "Option::is_none")] - pub user_agent: Option, + user_agent: Option, +} + +impl ClientConfig { + /// Set a custom user agent string for HTTP requests. + /// This is intended for internal use by language bindings. + pub fn with_user_agent(mut self, user_agent: impl Into) -> Self { + self.user_agent = Some(user_agent.into()); + self + } + + pub(crate) fn user_agent(&self) -> Option<&str> { + self.user_agent.as_deref() + } } /// Determines query serialization format for HTTP requests. diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index e58de3c..123154f 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -74,7 +74,8 @@ impl Client { .unwrap_or(NonZeroU64::new(30_000).unwrap()); let user_agent = cfg - .user_agent + .user_agent() + .map(|s| s.to_string()) .unwrap_or_else(|| format!("hypersync-client-rust/{}", env!("CARGO_PKG_VERSION"))); let http_client = reqwest::Client::builder() From 1c312491b7d844eb86f70e429103b9744a8d1153 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Oct 2025 22:45:31 +0200 Subject: [PATCH 3/7] Update user agent format in client to use abbreviation "hscr" instead of full name --- hypersync-client/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index 123154f..eb26127 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -76,7 +76,8 @@ impl Client { let user_agent = cfg .user_agent() .map(|s| s.to_string()) - .unwrap_or_else(|| format!("hypersync-client-rust/{}", env!("CARGO_PKG_VERSION"))); + // hscr stands for hypersync client rust + .unwrap_or_else(|| format!("hscr/{}", env!("CARGO_PKG_VERSION"))); let http_client = reqwest::Client::builder() .no_gzip() From e6c2f918e100f0cddc439aabff34bc10a8e78dd8 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 28 Oct 2025 13:33:51 +0200 Subject: [PATCH 4/7] Make the user agent abreviated --- hypersync-client/src/config.rs | 9 +++------ hypersync-client/src/lib.rs | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/hypersync-client/src/config.rs b/hypersync-client/src/config.rs index d7020b1..d2103fc 100644 --- a/hypersync-client/src/config.rs +++ b/hypersync-client/src/config.rs @@ -25,8 +25,9 @@ pub struct ClientConfig { #[serde(default)] pub serialization_format: SerializationFormat, /// Custom user agent string for HTTP requests. - #[serde(skip_serializing_if = "Option::is_none")] - user_agent: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + #[doc(hidden)] + pub user_agent: Option, } impl ClientConfig { @@ -36,10 +37,6 @@ impl ClientConfig { self.user_agent = Some(user_agent.into()); self } - - pub(crate) fn user_agent(&self) -> Option<&str> { - self.user_agent.as_deref() - } } /// Determines query serialization format for HTTP requests. diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index eb26127..304b06e 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -74,8 +74,7 @@ impl Client { .unwrap_or(NonZeroU64::new(30_000).unwrap()); let user_agent = cfg - .user_agent() - .map(|s| s.to_string()) + .user_agent // hscr stands for hypersync client rust .unwrap_or_else(|| format!("hscr/{}", env!("CARGO_PKG_VERSION"))); From 2f397ccae62b1776bb0cca582393f431ae78e561 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 28 Oct 2025 15:09:05 +0200 Subject: [PATCH 5/7] Update version for publish --- hypersync-client/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hypersync-client/Cargo.toml b/hypersync-client/Cargo.toml index 29d997e..6e0aeed 100644 --- a/hypersync-client/Cargo.toml +++ b/hypersync-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hypersync-client" -version = "0.20.0-rc.3" +version = "0.20.0-rc.4" edition = "2021" description = "client library for hypersync" license = "MPL-2.0" From 123ecc55bb3584801f8e7ab857f12fc785c5d63f Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 7 Nov 2025 16:21:23 +0200 Subject: [PATCH 6/7] Refactor ClientConfig to remove public user agent field and add additional client initialization for this --- hypersync-client/src/config.rs | 13 ------------- hypersync-client/src/lib.rs | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/hypersync-client/src/config.rs b/hypersync-client/src/config.rs index d2103fc..0b1d8be 100644 --- a/hypersync-client/src/config.rs +++ b/hypersync-client/src/config.rs @@ -24,19 +24,6 @@ pub struct ClientConfig { /// Query serialization format to use for HTTP requests. #[serde(default)] pub serialization_format: SerializationFormat, - /// Custom user agent string for HTTP requests. - #[serde(default, skip_serializing_if = "Option::is_none")] - #[doc(hidden)] - pub user_agent: Option, -} - -impl ClientConfig { - /// Set a custom user agent string for HTTP requests. - /// This is intended for internal use by language bindings. - pub fn with_user_agent(mut self, user_agent: impl Into) -> Self { - self.user_agent = Some(user_agent.into()); - self - } } /// Determines query serialization format for HTTP requests. diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index 304b06e..56798f8 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -69,15 +69,24 @@ pub struct Client { impl Client { /// Creates a new client with the given configuration. pub fn new(cfg: ClientConfig) -> Result { + // hscr stands for hypersync client rust + let user_agent = format!("hscr/{}", env!("CARGO_PKG_VERSION")); + Self::new_internal(cfg, user_agent) + } + + #[doc(hidden)] + pub fn new_with_agent(cfg: ClientConfig, user_agent: impl Into) -> Result { + // Creates a new client with the given configuration and custom user agent. + // This is intended for use by language bindings (Python, Node.js) and HyperIndex. + Self::new_internal(cfg, user_agent.into()) + } + + /// Internal constructor that takes both config and user agent. + fn new_internal(cfg: ClientConfig, user_agent: String) -> Result { let timeout = cfg .http_req_timeout_millis .unwrap_or(NonZeroU64::new(30_000).unwrap()); - let user_agent = cfg - .user_agent - // hscr stands for hypersync client rust - .unwrap_or_else(|| format!("hscr/{}", env!("CARGO_PKG_VERSION"))); - let http_client = reqwest::Client::builder() .no_gzip() .timeout(Duration::from_millis(timeout.get())) From f435eb421ed04ec40f14a17044373abab8c1f7a9 Mon Sep 17 00:00:00 2001 From: Jason Smythe Date: Fri, 7 Nov 2025 17:03:07 +0200 Subject: [PATCH 7/7] Apply suggestions from code review --- hypersync-client/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hypersync-client/Cargo.toml b/hypersync-client/Cargo.toml index 6e0aeed..00545bb 100644 --- a/hypersync-client/Cargo.toml +++ b/hypersync-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hypersync-client" -version = "0.20.0-rc.4" +version = "0.20.0-rc.5" edition = "2021" description = "client library for hypersync" license = "MPL-2.0"