From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B537E77A0B for ; Wed, 28 Apr 2021 16:24:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A41C9FE7F for ; Wed, 28 Apr 2021 16:23:41 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A05B5FE73 for ; Wed, 28 Apr 2021 16:23:40 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6FD46462A5 for ; Wed, 28 Apr 2021 16:23:40 +0200 (CEST) Date: Wed, 28 Apr 2021 16:23:39 +0200 From: Wolfgang Bumiller To: Dietmar Maurer Cc: pbs-devel@lists.proxmox.com Message-ID: <20210428142339.rvaisxu3shiwrckk@wobu-vie.proxmox.com> References: <20210428100358.25850-1-dietmar@proxmox.com> <20210428100358.25850-2-dietmar@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210428100358.25850-2-dietmar@proxmox.com> User-Agent: NeoMutt/20180716 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.034 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pbs-devel] [PATCH proxmox-backup 2/2] tools/http: make user agent configurable X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Apr 2021 14:24:11 -0000 Do we really need to have more than 1 user agent string in what's basically a non-exported utility, though? On Wed, Apr 28, 2021 at 12:03:58PM +0200, Dietmar Maurer wrote: > --- > src/tools/http.rs | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/src/tools/http.rs b/src/tools/http.rs > index a4299fb4..8656e685 100644 > --- a/src/tools/http.rs > +++ b/src/tools/http.rs > @@ -103,6 +103,7 @@ impl ProxyConfig { > pub struct SimpleHttp { > client: Client, > proxy_authorization: Option, // Proxy-Authorization header value > + user_agent: Option, > } > > impl SimpleHttp { > @@ -129,7 +130,12 @@ impl SimpleHttp { > https.set_proxy(proxy_config); > } > let client = Client::builder().build(https); > - Self { client, proxy_authorization} > + Self { client, proxy_authorization, user_agent: None } > + } > + > + pub fn set_user_agent(&mut self, user_agent: &str) -> Result<(), Error> { > + self.user_agent = Some(user_agent.to_owned()); > + Ok(()) > } > > fn add_proxy_headers(&self, request: &mut Request) -> Result<(), Error> { > @@ -147,11 +153,13 @@ impl SimpleHttp { > } > > pub async fn request(&self, mut request: Request) -> Result, Error> { > + let user_agent = if let Some(ref user_agent) = self.user_agent { > + HeaderValue::from_str(&user_agent)? > + } else { > + HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)? > + }; > > - request.headers_mut().insert( > - hyper::header::USER_AGENT, > - HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)?, > - ); > + request.headers_mut().insert(hyper::header::USER_AGENT, user_agent); > > self.add_proxy_headers(&mut request)?; > > -- > 2.20.1