public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox 1/2] http: sync client: add HTTP request timeout option
Date: Fri, 22 Nov 2024 11:08:14 +0100	[thread overview]
Message-ID: <20241122100815.67255-1-l.wagner@proxmox.com> (raw)

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 <l.wagner@proxmox.com>
---
 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<Duration>,
 }
 
 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<ureq::Agent, Error> {
         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


             reply	other threads:[~2024-11-22 10:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22 10:08 Lukas Wagner [this message]
2024-11-22 10:08 ` [pve-devel] [PATCH proxmox 2/2] notify: webhook: gotify: set HTTP request timeout Lukas Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241122100815.67255-1-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal