* [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets
@ 2021-04-09 8:14 Dominik Csapak
2021-05-04 10:54 ` Dominik Csapak
2021-05-04 11:17 ` Wolfgang Bumiller
0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2021-04-09 8:14 UTC (permalink / raw)
To: pbs-devel
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>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets
2021-04-09 8:14 [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets Dominik Csapak
@ 2021-05-04 10:54 ` Dominik Csapak
2021-05-04 11:17 ` Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2021-05-04 10:54 UTC (permalink / raw)
To: pbs-devel
ping
On 4/9/21 10:14, Dominik Csapak wrote:
> 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>
> ---
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets
2021-04-09 8:14 [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets Dominik Csapak
2021-05-04 10:54 ` Dominik Csapak
@ 2021-05-04 11:17 ` Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2021-05-04 11:17 UTC (permalink / raw)
To: Dominik Csapak; +Cc: pbs-devel
On Fri, Apr 09, 2021 at 10:14:56AM +0200, Dominik Csapak wrote:
> 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>
> ---
> we could also only add it to the actual request if wanted, should not
> make much of a difference though
^ That would definitely be the better approach, because with the current
patch you're also changing the address for *everything* else
(load_fingerprint, store_fingerprint, store_ticket_info, ...)
The address is supposed to be just that, an address. The brackets are
part of the URL syntax and should therefore be limited to that and that
alone.
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-04 11:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 8:14 [pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets Dominik Csapak
2021-05-04 10:54 ` Dominik Csapak
2021-05-04 11:17 ` Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox