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