all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dylan Whyte <d.whyte@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 proxmox-backup 2/2] tools-http: Add proxy option for get_string
Date: Tue, 30 Mar 2021 16:47:25 +0200	[thread overview]
Message-ID: <20210330144725.7892-2-d.whyte@proxmox.com> (raw)
In-Reply-To: <20210330144725.7892-1-d.whyte@proxmox.com>

Adds a proxy argument to the get_string function, which will use the
proxy connector if it has a value. Also updates calls to the function to
avoid breakages

Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
---

I decided to add this in with the fix, although it currently has no
effect. Again, once the situation with the administration config file
is understood, I can get the proxy from that.

 src/api2/node/apt.rs |  6 ++++--
 src/tools/http.rs    | 12 ++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs
index e77b89fa..3395fe1d 100644
--- a/src/api2/node/apt.rs
+++ b/src/api2/node/apt.rs
@@ -197,7 +197,8 @@ fn apt_get_changelog(
     let changelog_url = &pkg_info[0].change_log_url;
     // FIXME: use 'apt-get changelog' for proxmox packages as well, once repo supports it
     if changelog_url.starts_with("http://download.proxmox.com/") {
-        let changelog = crate::tools::runtime::block_on(http::get_string(changelog_url, None))
+        // FIXME: get http_proxy from config file
+        let changelog = crate::tools::runtime::block_on(http::get_string(changelog_url, None, None))
             .map_err(|err| format_err!("Error downloading changelog from '{}': {}", changelog_url, err))?;
         Ok(json!(changelog))
 
@@ -221,7 +222,8 @@ fn apt_get_changelog(
         auth_header.insert("Authorization".to_owned(),
             format!("Basic {}", base64::encode(format!("{}:{}", key, id))));
 
-        let changelog = crate::tools::runtime::block_on(http::get_string(changelog_url, Some(&auth_header)))
+        // FIXME: get http_proxy from config file
+        let changelog = crate::tools::runtime::block_on(http::get_string(changelog_url, Some(&auth_header), None))
             .map_err(|err| format_err!("Error downloading changelog from '{}': {}", changelog_url, err))?;
         Ok(json!(changelog))
 
diff --git a/src/tools/http.rs b/src/tools/http.rs
index 8d940d01..ea32946c 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -29,7 +29,10 @@ lazy_static! {
     };
 }
 
-pub async fn get_string(uri: &str, extra_headers: Option<&HashMap<String, String>>) -> Result<String, Error> {
+pub async fn get_string(uri: &str,
+                        extra_headers: Option<&HashMap<String, String>>,
+                        proxy: Option<String>
+                        ) -> Result<String, Error> {
     let mut request = Request::builder()
         .method("GET")
         .uri(uri)
@@ -43,7 +46,12 @@ pub async fn get_string(uri: &str, extra_headers: Option<&HashMap<String, String
 
     let request = request.body(Body::empty())?;
 
-    let res = HTTP_CLIENT.request(request).await?;
+    let res = if let Some(proxy) = proxy {
+        let client = proxy_connector(proxy)?;
+        client.request(request).await?
+    } else {
+        HTTP_CLIENT.request(request).await?
+    };
 
     let status = res.status();
     if !status.is_success() {
-- 
2.20.1





      reply	other threads:[~2021-03-30 14:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 14:47 [pbs-devel] [PATCH v2 proxmox-backup 1/2] fix #3296: allow set subscription through proxy Dylan Whyte
2021-03-30 14:47 ` Dylan Whyte [this message]

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=20210330144725.7892-2-d.whyte@proxmox.com \
    --to=d.whyte@proxmox.com \
    --cc=pbs-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