From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2] client/http_client: add necessary brackets
Date: Tue, 4 May 2021 15:01:38 +0200 [thread overview]
Message-ID: <20210504130138.32568-1-d.csapak@proxmox.com> (raw)
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@proxmox.com>
---
changes from v1:
* move the actual mapping to the request building functions
src/client/http_client.rs | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/client/http_client.rs b/src/client/http_client.rs
index 76ab0391..ab7bda48 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,
@@ -615,7 +625,8 @@ impl HttpClient {
) -> Result<Value, Error> {
let path = path.trim_matches('/');
- let mut url = format!("https://{}:{}/{}", &self.server, self.port, path);
+ let server = map_ipv6(&self.server);
+ let mut url = format!("https://{}:{}/{}", server, self.port, path);
if let Some(data) = data {
let query = tools::json_object_to_query(data).unwrap();
@@ -758,6 +769,7 @@ impl HttpClient {
pub fn request_builder(server: &str, port: u16, method: &str, path: &str, data: Option<Value>) -> Result<Request<Body>, Error> {
let path = path.trim_matches('/');
+ let server = map_ipv6(server);
let url: Uri = format!("https://{}:{}/{}", server, port, path).parse()?;
if let Some(data) = data {
@@ -970,6 +982,7 @@ impl H2Client {
let path = path.trim_matches('/');
let content_type = content_type.unwrap_or("application/x-www-form-urlencoded");
+ let server = map_ipv6(server);
if let Some(param) = param {
let query = tools::json_object_to_query(param)?;
--
2.20.1
reply other threads:[~2021-05-04 13:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210504130138.32568-1-d.csapak@proxmox.com \
--to=d.csapak@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