[pbs-devel] [PATCH v2 backup 16/27] tools/http: add request_with_agent helper

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Apr 22 16:02:02 CEST 2021


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

diff --git a/src/tools/http.rs b/src/tools/http.rs
index 31dea33a..55c8e41e 100644
--- a/src/tools/http.rs
+++ b/src/tools/http.rs
@@ -60,6 +60,15 @@ impl SimpleHttp {
         Self { client }
     }
 
+    /// Helper to finish a request with our user agent string and perform the request:
+    pub async fn request_with_agent(
+        &mut self,
+        request: http::request::Builder,
+        body: Body,
+    ) -> Result<Response<Body>, Error> {
+        self.request(request.header("User-Agent", USER_AGENT_STRING).body(body)?).await
+    }
+
     pub async fn request(&self, request: Request<Body>) -> Result<Response<Body>, Error> {
         self.client.request(request)
             .map_err(Error::from)
-- 
2.20.1






More information about the pbs-devel mailing list