From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E709B79E7E for ; Thu, 6 May 2021 10:30:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D830C1D388 for ; Thu, 6 May 2021 10:30:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id A2F221D378 for ; Thu, 6 May 2021 10:30:42 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7802042934 for ; Thu, 6 May 2021 10:30:42 +0200 (CEST) To: Proxmox Backup Server development discussion , Wolfgang Bumiller References: <20210506065544.28924-1-w.bumiller@proxmox.com> From: Dietmar Maurer Message-ID: <81b2852a-1c72-1ae0-a5ea-d144c55c462f@proxmox.com> Date: Thu, 6 May 2021 10:30:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210506065544.28924-1-w.bumiller@proxmox.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-SPAM-LEVEL: Spam detection results: 0 AWL 0.233 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [http.rs] Subject: [pbs-devel] applied: [PATCH backup] client: use build_authority in build_uri X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2021 08:30:43 -0000 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 > --- > 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) -> Result { > - 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 { > +pub(crate) fn build_authority(host: &str, port: u16) -> Result { > let bytes = host.as_bytes(); > let len = bytes.len(); > let authority = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {