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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 63ACF79E0B for ; Thu, 6 May 2021 08:55:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 578911BEDD for ; Thu, 6 May 2021 08:55:50 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 273EA1BED2 for ; Thu, 6 May 2021 08:55:49 +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 EED5342965 for ; Thu, 6 May 2021 08:55:48 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Thu, 6 May 2021 08:55:44 +0200 Message-Id: <20210506065544.28924-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.018 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] [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 06:55:50 -0000 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']' { -- 2.20.1