[pbs-devel] [RFC backup 04/23] tools::http: generic 'fn request' and dedup agent string

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Apr 16 15:34:57 CEST 2021


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/tools/http.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/tools/http.rs b/src/tools/http.rs
index d08ce451..136a678f 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -28,11 +28,17 @@ lazy_static! {
     };
 }
 
+const USER_AGENT_STRING: &str = "proxmox-backup-client/1.0";
+
+pub async fn request(request: http::request::Builder, body: Body) -> Result<Response<Body>, Error> {
+    Ok(HTTP_CLIENT.request(request.header("User-Agent", USER_AGENT_STRING).body(body)?).await?)
+}
+
 pub async fn get_string(uri: &str, extra_headers: Option<&HashMap<String, String>>) -> Result<String, Error> {
     let mut request = Request::builder()
         .method("GET")
         .uri(uri)
-        .header("User-Agent", "proxmox-backup-client/1.0");
+        .header("User-Agent", USER_AGENT_STRING);
 
     if let Some(hs) = extra_headers {
         for (h, v) in hs.iter() {
@@ -73,7 +79,7 @@ pub async fn post(
     let request = Request::builder()
         .method("POST")
         .uri(uri)
-        .header("User-Agent", "proxmox-backup-client/1.0")
+        .header("User-Agent", USER_AGENT_STRING)
         .header(hyper::header::CONTENT_TYPE, content_type)
         .body(body)?;
 
-- 
2.20.1






More information about the pbs-devel mailing list