From: Dietmar Maurer <dietmar@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: [pbs-devel] applied: [PATCH backup] client: use build_authority in build_uri
Date: Thu, 6 May 2021 10:30:41 +0200 [thread overview]
Message-ID: <81b2852a-1c72-1ae0-a5ea-d144c55c462f@proxmox.com> (raw)
In-Reply-To: <20210506065544.28924-1-w.bumiller@proxmox.com>
applied, after moving SimpleHttp client code into extra file
On 5/6/21 8:55 AM, Wolfgang Bumiller wrote:
> so we don't need to also duplicate the IPv6 bracket logic
>
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
> Just a little cleanup since we added 2 different bracket codes for ipv6
> in the recent commits...
>
> src/client/http_client.rs | 31 +++++++++++++------------------
> src/tools/http.rs | 2 +-
> 2 files changed, 14 insertions(+), 19 deletions(-)
>
> diff --git a/src/client/http_client.rs b/src/client/http_client.rs
> index f2fada23..785626e8 100644
> --- a/src/client/http_client.rs
> +++ b/src/client/http_client.rs
> @@ -26,7 +26,10 @@ use crate::tools::{
> self,
> BroadcastFuture,
> DEFAULT_ENCODE_SET,
> - http::HttpsConnector,
> + http::{
> + build_authority,
> + HttpsConnector,
> + },
> };
>
> /// Timeout used for several HTTP operations that are expected to finish quickly but may block in
> @@ -274,23 +277,15 @@ fn load_ticket_info(prefix: &str, server: &str, userid: &Userid) -> Option<(Stri
> }
>
> fn build_uri(server: &str, port: u16, path: &str, query: Option<String>) -> Result<Uri, Error> {
> - let path = path.trim_matches('/');
> - let bytes = server.as_bytes();
> - let len = bytes.len();
> - let uri = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
> - if let Some(query) = query {
> - format!("https://[{}]:{}/{}?{}", server, port, path, query)
> - } else {
> - format!("https://[{}]:{}/{}", server, port, path)
> - }
> - } else {
> - if let Some(query) = query {
> - format!("https://{}:{}/{}?{}", server, port, path, query)
> - } else {
> - format!("https://{}:{}/{}", server, port, path)
> - }
> - };
> - Ok(uri.parse()?)
> + let builder = Uri::builder()
> + .scheme("https")
> + .authority(build_authority(server, port)?);
> + match query {
> + Some(query) => builder.path_and_query(format!("{}?{}", path, query)),
> + None => builder.path_and_query(path),
> + }
> + .build()
> + .map_err(Error::from)
> }
>
> impl HttpClient {
> diff --git a/src/tools/http.rs b/src/tools/http.rs
> index cfdd9b16..9adfc118 100644
> --- a/src/tools/http.rs
> +++ b/src/tools/http.rs
> @@ -29,7 +29,7 @@ use crate::tools::{
> };
>
> // Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses
> -fn build_authority(host: &str, port: u16) -> Result<Authority, Error> {
> +pub(crate) fn build_authority(host: &str, port: u16) -> Result<Authority, Error> {
> let bytes = host.as_bytes();
> let len = bytes.len();
> let authority = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
prev parent reply other threads:[~2021-05-06 8:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-06 6:55 [pbs-devel] " Wolfgang Bumiller
2021-05-06 8:30 ` Dietmar Maurer [this message]
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=81b2852a-1c72-1ae0-a5ea-d144c55c462f@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=w.bumiller@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.