feat/refactor: add Client::request_with_host, move main code into it

This commit is contained in:
DarkCat09 2024-08-01 20:16:28 +04:00
parent d462cd4fbe
commit 86fb310e71
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -52,7 +52,18 @@ impl Client {
} }
let host = url.host_str().ok_or(InvalidUrl::ConvertError)?; let host = url.host_str().ok_or(InvalidUrl::ConvertError)?;
let addr = (host, url.port().unwrap_or(1965)) let port = url.port().unwrap_or(1965);
self.request_with_host(url_str, host, port).await
}
pub async fn request_with_host(
self: &Self,
url_str: &str,
host: &str,
port: u16,
) -> Result<Response, LibError> {
let addr = (host, port)
.to_socket_addrs()? .to_socket_addrs()?
.next() .next()
.ok_or(InvalidUrl::ConvertError)?; .ok_or(InvalidUrl::ConvertError)?;