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 90926777A4 for ; Wed, 28 Apr 2021 12:04:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 833B19F67 for ; Wed, 28 Apr 2021 12:04:04 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 11C2F9F5E for ; Wed, 28 Apr 2021 12:04:04 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id E8B5AAEB223; Wed, 28 Apr 2021 12:04:03 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Wed, 28 Apr 2021 12:03:57 +0200 Message-Id: <20210428100358.25850-1-dietmar@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.140 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 1/2] tools/http: set USER_AGENT inside request 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 10:04:34 -0000 --- src/tools/http.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tools/http.rs b/src/tools/http.rs index f4ccefc9..a4299fb4 100644 --- a/src/tools/http.rs +++ b/src/tools/http.rs @@ -107,6 +107,8 @@ pub struct SimpleHttp { impl SimpleHttp { + pub const DEFAULT_USER_AGENT_STRING: &'static str = "proxmox-backup-client/1.0"; + pub fn new(proxy_config: Option) -> Self { let ssl_connector = SslConnector::builder(SslMethod::tls()).unwrap().build(); Self::with_ssl_connector(ssl_connector, proxy_config) @@ -145,7 +147,14 @@ impl SimpleHttp { } pub async fn request(&self, mut request: Request) -> Result, Error> { + + request.headers_mut().insert( + hyper::header::USER_AGENT, + HeaderValue::from_str(Self::DEFAULT_USER_AGENT_STRING)?, + ); + self.add_proxy_headers(&mut request)?; + self.client.request(request) .map_err(Error::from) .await @@ -168,7 +177,6 @@ impl SimpleHttp { let request = Request::builder() .method("POST") .uri(uri) - .header("User-Agent", "proxmox-backup-client/1.0") .header(hyper::header::CONTENT_TYPE, content_type) .body(body)?; @@ -183,8 +191,7 @@ impl SimpleHttp { let mut request = Request::builder() .method("GET") - .uri(uri) - .header("User-Agent", "proxmox-backup-client/1.0"); + .uri(uri); if let Some(hs) = extra_headers { for (h, v) in hs.iter() { -- 2.20.1