diff --git a/common/http-api-client/src/lib.rs b/common/http-api-client/src/lib.rs index 564d6874bb9..64359c96e79 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 1543798a6a0..f46a2038ae7 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);