[pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets

Dominik Csapak d.csapak at proxmox.com
Fri Apr 9 10:14:56 CEST 2021


if we are given a 'naked' ipv6 without square brackets around it,
we need to add them ourselves, since the address is ambigious otherwise
when we add the port.

e.g. giving 'fe80::1' as address we arrive at the url (with the default port)
'https://fe80::1:8007/'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
we could also only add it to the actual request if wanted, should not
make much of a difference though

 src/client/http_client.rs | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/client/http_client.rs b/src/client/http_client.rs
index 76ab0391..07e8cd83 100644
--- a/src/client/http_client.rs
+++ b/src/client/http_client.rs
@@ -273,6 +273,16 @@ fn load_ticket_info(prefix: &str, server: &str, userid: &Userid) -> Option<(Stri
     }
 }
 
+fn map_ipv6(server: &str) -> String {
+    let bytes = server.as_bytes();
+    let len = bytes.len();
+    if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
+        format!("[{}]", server)
+    } else {
+        server.to_string()
+    }
+}
+
 impl HttpClient {
     pub fn new(
         server: &str,
@@ -285,11 +295,13 @@ impl HttpClient {
 
         let mut fingerprint = options.fingerprint.take();
 
+        let server = map_ipv6(server);
+
         if fingerprint.is_some() {
             // do not store fingerprints passed via options in cache
             options.fingerprint_cache = false;
         } else if options.fingerprint_cache && options.prefix.is_some() {
-            fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), server);
+            fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), &server);
         }
 
         let mut ssl_connector_builder = SslConnector::builder(SslMethod::tls()).unwrap();
@@ -344,7 +356,7 @@ impl HttpClient {
             };
             let mut ticket_info = None;
             if use_ticket_cache {
-                ticket_info = load_ticket_info(options.prefix.as_ref().unwrap(), server, userid);
+                ticket_info = load_ticket_info(options.prefix.as_ref().unwrap(), &server, userid);
             }
             if let Some((ticket, _token)) = ticket_info {
                 ticket
-- 
2.20.1






More information about the pbs-devel mailing list