http: sync: derive default user-agent from crate version

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2023-03-03 12:39:23 +01:00 committed by Wolfgang Bumiller
parent 5ba9d9b2c2
commit 6a1be173a6

View File

@ -7,8 +7,6 @@ use http::Response;
use crate::HttpClient; use crate::HttpClient;
use crate::HttpOptions; use crate::HttpOptions;
pub const DEFAULT_USER_AGENT_STRING: &str = "proxmox-sync-http-client/0.1";
#[derive(Default)] #[derive(Default)]
/// Blocking HTTP client for usage with [`HttpClient`]. /// Blocking HTTP client for usage with [`HttpClient`].
pub struct Client { pub struct Client {
@ -23,12 +21,10 @@ impl Client {
fn agent(&self) -> Result<ureq::Agent, Error> { fn agent(&self) -> Result<ureq::Agent, Error> {
let mut builder = ureq::AgentBuilder::new(); let mut builder = ureq::AgentBuilder::new();
builder = builder.user_agent( builder = builder.user_agent(self.options.user_agent.as_deref().unwrap_or(&format!(
self.options "proxmox-sync-http-client/{}",
.user_agent env!("CARGO_PKG_VERSION")
.as_deref() )));
.unwrap_or(DEFAULT_USER_AGENT_STRING),
);
if let Some(proxy_config) = &self.options.proxy_config { if let Some(proxy_config) = &self.options.proxy_config {
builder = builder.proxy(ureq::Proxy::new(proxy_config.to_proxy_string()?)?); builder = builder.proxy(ureq::Proxy::new(proxy_config.to_proxy_string()?)?);