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 C11E97097A for ; Fri, 14 May 2021 15:45:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BD11B17A70 for ; Fri, 14 May 2021 15:45:06 +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 328D117A64 for ; Fri, 14 May 2021 15:45:06 +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 0663E46571 for ; Fri, 14 May 2021 15:45:06 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Fri, 14 May 2021 15:44:43 +0200 Message-Id: <20210514134457.1447930-8-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> References: <20210514134457.1447930-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 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. [helpers.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox 07/13] http: takeover build_authority helper from proxmox_backup 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: Fri, 14 May 2021 13:45:06 -0000 Signed-off-by: Fabian Grünbichler --- proxmox-http/Cargo.toml | 3 ++- proxmox-http/src/http/helpers.rs | 15 +++++++++++++++ proxmox-http/src/http/mod.rs | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 proxmox-http/src/http/helpers.rs diff --git a/proxmox-http/Cargo.toml b/proxmox-http/Cargo.toml index f1f53da..6b2d8db 100644 --- a/proxmox-http/Cargo.toml +++ b/proxmox-http/Cargo.toml @@ -15,6 +15,7 @@ exclude = [ "debian" ] anyhow = "1.0" base64 = { version = "0.12", optional = true } futures = { version = "0.3", optional = true } +http = { version = "0.2", optional = true } hyper = { version = "0.14", features = [ "full" ], optional = true } openssl = { version = "0.10", optional = true } tokio = { version = "1.0", features = [], optional = true } @@ -26,5 +27,5 @@ proxmox = { path = "../proxmox", optional = true, version = "0.11.3", default-fe default = [] client = [ "http-helpers" ] -http-helpers = [ "hyper", "tokio/io-util", "tokio-openssl" ] +http-helpers = [ "http", "hyper", "tokio/io-util", "tokio-openssl" ] websocket = [ "base64", "futures", "hyper", "openssl", "proxmox/tokio", "tokio/io-util", "tokio/sync" ] diff --git a/proxmox-http/src/http/helpers.rs b/proxmox-http/src/http/helpers.rs new file mode 100644 index 0000000..3f663d2 --- /dev/null +++ b/proxmox-http/src/http/helpers.rs @@ -0,0 +1,15 @@ +use anyhow::Error; + +use http::uri::Authority; + +// Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses +pub 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']' { + format!("[{}]:{}", host, port).parse()? + } else { + format!("{}:{}", host, port).parse()? + }; + Ok(authority) +} diff --git a/proxmox-http/src/http/mod.rs b/proxmox-http/src/http/mod.rs index 09fa42f..4960246 100644 --- a/proxmox-http/src/http/mod.rs +++ b/proxmox-http/src/http/mod.rs @@ -1,3 +1,5 @@ mod wrapper; pub use wrapper::MaybeTlsStream; + +pub mod helpers; -- 2.20.1