all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Mira Limbeck <m.limbeck@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-openid-rs] add http proxy support
Date: Mon, 21 Mar 2022 14:24:54 +0100	[thread overview]
Message-ID: <20220321132454.3959858-1-m.limbeck@proxmox.com> (raw)

ureq has support for a HTTP proxy, but no support for HTTPS proxy yet.

ureq doesn't query `all_proxy` and `ALL_PROXY` environment variables by
itself the way curl does. So set the proxy in code if any of the above
environment variables are set.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
 src/http_client.rs | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/http_client.rs b/src/http_client.rs
index 5cceafb..a732a98 100644
--- a/src/http_client.rs
+++ b/src/http_client.rs
@@ -40,9 +40,18 @@ pub enum Error {
 }
 
 fn ureq_agent() -> Result<ureq::Agent, Error> {
-    Ok(ureq::AgentBuilder::new()
-        .tls_connector(Arc::new(native_tls::TlsConnector::new()?))
-        .build())
+    let mut agent = 
+        ureq::AgentBuilder::new().tls_connector(Arc::new(native_tls::TlsConnector::new()?));
+    if let Ok(val) = std::env::var("all_proxy") {
+        let proxy = ureq::Proxy::new(val).map_err(Box::new)?;
+        agent = agent.proxy(proxy);
+    } else if let Ok(val) = std::env::var("ALL_PROXY") {
+        let proxy = ureq::Proxy::new(val).map_err(Box::new)?;
+        agent = agent.proxy(proxy);
+    }
+
+
+    Ok(agent.build())
 }
 
 ///
-- 
2.30.2





             reply	other threads:[~2022-03-21 13:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 13:24 Mira Limbeck [this message]
2022-03-21 14:58 ` Wolfgang Bumiller

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=20220321132454.3959858-1-m.limbeck@proxmox.com \
    --to=m.limbeck@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal