diff --git a/hypersync-client/Cargo.toml b/hypersync-client/Cargo.toml index 29d997e..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.3" +version = "0.20.0-rc.5" edition = "2021" description = "client library for hypersync" license = "MPL-2.0" diff --git a/hypersync-client/src/lib.rs b/hypersync-client/src/lib.rs index b9c2bb5..56798f8 100644 --- a/hypersync-client/src/lib.rs +++ b/hypersync-client/src/lib.rs @@ -69,6 +69,20 @@ 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()); @@ -76,6 +90,7 @@ impl Client { let http_client = reqwest::Client::builder() .no_gzip() .timeout(Duration::from_millis(timeout.get())) + .user_agent(user_agent) .build() .unwrap();