[pbs-devel] [PATCH v2 proxmox-backup 2/2] tools-http: Add proxy option for get_string

Dylan Whyte d.whyte at proxmox.com
Tue Mar 30 16:47:25 CEST 2021


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 at 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






More information about the pbs-devel mailing list