From 979485c5826157b2bfeeec2c454645e1d9c6aba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 13 Aug 2025 12:52:16 +0100 Subject: [PATCH] http api client adjustment (#5953) * missing feature lock for attempting to clone client * added helper macro to generate user agent without additional imports --- common/http-api-client/src/lib.rs | 5 +++++ common/http-api-client/src/user_agent.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 564d6874bb..64359c96e7 100644 --- a/common/http-api-client/src/lib.rs +++ b/common/http-api-client/src/lib.rs @@ -173,6 +173,10 @@ mod path; #[cfg(not(target_arch = "wasm32"))] pub use dns::{HickoryDnsError, HickoryDnsResolver}; +// helper for generating user agent based on binary information +#[doc(hidden)] +pub use nym_bin_common::bin_info; + /// Default HTTP request connection timeout. /// /// The timeout is relatively high as we are often making requests over the mixnet, where latency is @@ -608,6 +612,7 @@ impl Client { current_idx: Arc::new(Default::default()), reqwest_client: self.reqwest_client.clone(), + #[cfg(feature = "tunneling")] front: self.front.clone(), retry_limit: self.retry_limit, diff --git a/common/http-api-client/src/user_agent.rs b/common/http-api-client/src/user_agent.rs index 1543798a6a..f46a2038ae 100644 --- a/common/http-api-client/src/user_agent.rs +++ b/common/http-api-client/src/user_agent.rs @@ -20,6 +20,16 @@ pub struct UserAgent { pub git_commit: String, } +/// Create `UserAgent` based on the caller's crate information +// we can't use normal function as then `application` and `version` would correspond +// of that of `nym-http-api-client` lib +#[macro_export] +macro_rules! generate_user_agent { + () => { + $crate::UserAgent::from($crate::bin_info!()) + }; +} + #[derive(Clone, Debug, thiserror::Error)] #[error("invalid user agent string: {0}")] pub struct UserAgentError(String);