From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 9AB0E1FF164 for ; Fri, 22 Nov 2024 11:08:18 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E6353F498; Fri, 22 Nov 2024 11:08:24 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Fri, 22 Nov 2024 11:08:14 +0100 Message-Id: <20241122100815.67255-1-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.009 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox 1/2] http: sync client: add HTTP request timeout option X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This commits adds the possibility to set a HTTP request timeout for the sync client. For now, I've opted to add this as a separate option than can be set via a separate new_with_timeout method as compared to adding it to the HttpOptions struct. While it of course would make a lot of sense to add it to the latter, this would require adding support for request timeouts to the async client as well. Some users of the async client handle request timeouts externally via tokio::time::timeout, so these would need to modified as well. I don't want to touch this at the moment, so I've opted to introduce the timeout to the sync client only for now. We can always revisit this at a later time and move the option to the HttpOptions struct. Signed-off-by: Lukas Wagner --- proxmox-http/src/client/sync.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/proxmox-http/src/client/sync.rs b/proxmox-http/src/client/sync.rs index fb10f5be..955a6fce 100644 --- a/proxmox-http/src/client/sync.rs +++ b/proxmox-http/src/client/sync.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::io::Read; use std::sync::Arc; +use std::time::Duration; use anyhow::Error; use http::Response; @@ -12,16 +13,31 @@ use crate::HttpOptions; /// Blocking HTTP client for usage with [`HttpClient`]. pub struct Client { options: HttpOptions, + timeout: Option, } impl Client { pub fn new(options: HttpOptions) -> Self { - Self { options } + Self { + options, + timeout: None, + } + } + + pub fn new_with_timeout(options: HttpOptions, timeout: Duration) -> Self { + Self { + options, + timeout: Some(timeout), + } } fn agent(&self) -> Result { let mut builder = ureq::AgentBuilder::new(); + if let Some(timeout) = self.timeout { + builder = builder.timeout(timeout); + }; + let connector = Arc::new(native_tls::TlsConnector::new()?); builder = builder.tls_connector(connector); -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel