client: use build_authority in build_uri
so we don't need to also duplicate the IPv6 bracket logic Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
78bf292343
commit
25d78b1068
@ -26,7 +26,10 @@ use crate::tools::{
|
|||||||
self,
|
self,
|
||||||
BroadcastFuture,
|
BroadcastFuture,
|
||||||
DEFAULT_ENCODE_SET,
|
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
|
/// 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> {
|
fn build_uri(server: &str, port: u16, path: &str, query: Option<String>) -> Result<Uri, Error> {
|
||||||
let path = path.trim_matches('/');
|
let builder = Uri::builder()
|
||||||
let bytes = server.as_bytes();
|
.scheme("https")
|
||||||
let len = bytes.len();
|
.authority(build_authority(server, port)?);
|
||||||
let uri = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
|
match query {
|
||||||
if let Some(query) = query {
|
Some(query) => builder.path_and_query(format!("{}?{}", path, query)),
|
||||||
format!("https://[{}]:{}/{}?{}", server, port, path, query)
|
None => builder.path_and_query(path),
|
||||||
} else {
|
}
|
||||||
format!("https://[{}]:{}/{}", server, port, path)
|
.build()
|
||||||
}
|
.map_err(Error::from)
|
||||||
} else {
|
|
||||||
if let Some(query) = query {
|
|
||||||
format!("https://{}:{}/{}?{}", server, port, path, query)
|
|
||||||
} else {
|
|
||||||
format!("https://{}:{}/{}", server, port, path)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(uri.parse()?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpClient {
|
impl HttpClient {
|
||||||
|
@ -27,7 +27,7 @@ use crate::tools::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Build a http::uri::Authority ("host:port"), use '[..]' around IPv6 addresses
|
// 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 bytes = host.as_bytes();
|
||||||
let len = bytes.len();
|
let len = bytes.len();
|
||||||
let authority = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
|
let authority = if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
|
||||||
|
Loading…
Reference in New Issue
Block a user