mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 11:06:02 +00:00
http: takeover build_authority helper from proxmox_backup
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
6c5028512b
commit
f305be9583
@ -15,6 +15,7 @@ exclude = [ "debian" ]
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
base64 = { version = "0.12", optional = true }
|
base64 = { version = "0.12", optional = true }
|
||||||
futures = { version = "0.3", optional = true }
|
futures = { version = "0.3", optional = true }
|
||||||
|
http = { version = "0.2", optional = true }
|
||||||
hyper = { version = "0.14", features = [ "full" ], optional = true }
|
hyper = { version = "0.14", features = [ "full" ], optional = true }
|
||||||
openssl = { version = "0.10", optional = true }
|
openssl = { version = "0.10", optional = true }
|
||||||
tokio = { version = "1.0", features = [], 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 = []
|
default = []
|
||||||
|
|
||||||
client = [ "http-helpers" ]
|
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" ]
|
websocket = [ "base64", "futures", "hyper", "openssl", "proxmox/tokio", "tokio/io-util", "tokio/sync" ]
|
||||||
|
15
proxmox-http/src/http/helpers.rs
Normal file
15
proxmox-http/src/http/helpers.rs
Normal file
@ -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<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']' {
|
||||||
|
format!("[{}]:{}", host, port).parse()?
|
||||||
|
} else {
|
||||||
|
format!("{}:{}", host, port).parse()?
|
||||||
|
};
|
||||||
|
Ok(authority)
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
mod wrapper;
|
mod wrapper;
|
||||||
|
|
||||||
pub use wrapper::MaybeTlsStream;
|
pub use wrapper::MaybeTlsStream;
|
||||||
|
|
||||||
|
pub mod helpers;
|
||||||
|
Loading…
Reference in New Issue
Block a user