[pbs-devel] [PATCH proxmox 3/4] http: sync: derive default user-agent from crate version
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Mar 7 09:40:59 CET 2023
On Fri, Mar 03, 2023 at 12:39:23PM +0100, Fabian Grünbichler wrote:
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
> if we want a fall back in case rustc is called manually, not by cargo, we could
> also use option_env!..
>
> proxmox-http/src/client/sync.rs | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/proxmox-http/src/client/sync.rs b/proxmox-http/src/client/sync.rs
> index 228f839..3485f84 100644
> --- a/proxmox-http/src/client/sync.rs
> +++ b/proxmox-http/src/client/sync.rs
> @@ -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")
> + )));
I just realized too late that here this could actually use `concat!()`
instead of `&format!` to avoid the extra allocation.
>
> if let Some(proxy_config) = &self.options.proxy_config {
> builder = builder.proxy(ureq::Proxy::new(proxy_config.to_proxy_string()?)?);
> --
> 2.30.2
More information about the pbs-devel
mailing list