aboutsummaryrefslogtreecommitdiff
path: root/src/request
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-11 06:04:01 +0000
committerFuwn <[email protected]>2025-09-11 06:04:01 +0000
commit51e79294d8fbfb1bd4be8584e2d32ff0712227aa (patch)
treee77c766264366af78345c2e1da823e6610c852a6 /src/request
parentfix(request): Handle malformed response header (diff)
downloadgerm-51e79294d8fbfb1bd4be8584e2d32ff0712227aa.tar.xz
germ-51e79294d8fbfb1bd4be8584e2d32ff0712227aa.zip
fix(request): Handle invalid URLs
Diffstat (limited to 'src/request')
-rw-r--r--src/request/blocking.rs7
-rw-r--r--src/request/non_blocking.rs10
2 files changed, 13 insertions, 4 deletions
diff --git a/src/request/blocking.rs b/src/request/blocking.rs
index 2002ed8..984f886 100644
--- a/src/request/blocking.rs
+++ b/src/request/blocking.rs
@@ -44,13 +44,16 @@ pub fn request(url: &url::Url) -> anyhow::Result<Response> {
.with_safe_defaults()
.with_custom_certificate_verifier(std::sync::Arc::new(GermVerifier::new()))
.with_no_client_auth();
+ let domain = url
+ .domain()
+ .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?;
let mut connection = rustls::ClientConnection::new(
std::sync::Arc::new(config),
- url.domain().unwrap_or("").try_into()?,
+ domain.try_into()?,
)?;
let mut stream = std::net::TcpStream::connect(format!(
"{}:{}",
- url.domain().unwrap_or(""),
+ domain,
url.port().unwrap_or(1965)
))?;
let mut tls = rustls::Stream::new(&mut connection, &mut stream);
diff --git a/src/request/non_blocking.rs b/src/request/non_blocking.rs
index 3bbcd95..85856e7 100644
--- a/src/request/non_blocking.rs
+++ b/src/request/non_blocking.rs
@@ -55,10 +55,16 @@ pub async fn request(url: &url::Url) -> anyhow::Result<Response> {
.with_no_client_auth(),
))
.connect(
- rustls::ServerName::try_from(url.domain().unwrap_or_default())?,
+ rustls::ServerName::try_from(
+ url
+ .domain()
+ .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?,
+ )?,
tokio::net::TcpStream::connect(format!(
"{}:{}",
- url.domain().unwrap_or(""),
+ url
+ .domain()
+ .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?,
url.port().unwrap_or(1965)
))
.await?,