diff --git a/lychee-bin/tests/data_uris.rs b/lychee-bin/tests/data_uris.rs index 96b11ad4d3..c90451c0ee 100644 --- a/lychee-bin/tests/data_uris.rs +++ b/lychee-bin/tests/data_uris.rs @@ -53,4 +53,16 @@ mod cli { let output = std::str::from_utf8(&output.stdout).unwrap(); assert_eq!(output.lines().count(), 5); } + + #[test] + fn test_check_data_uris() { + let input = fixtures_path().join("TEST_DATA_URIS.html"); + + cargo_bin_cmd!() + .arg(input) + .arg("--exclude-loopback") + .assert() + .success() + .stdout(contains("3 Unsupported")); + } } diff --git a/lychee-lib/src/checker/website.rs b/lychee-lib/src/checker/website.rs index c490fc22b3..b2601dde5c 100644 --- a/lychee-lib/src/checker/website.rs +++ b/lychee-lib/src/checker/website.rs @@ -254,7 +254,7 @@ impl WebsiteChecker { let request = match request { Ok(r) => r, - Err(e) => return e.into(), + Err(e) => return Status::from(e), }; let status = ClientRequestChains::new(vec![&self.plugin_request_chain, default_chain]) diff --git a/lychee-lib/src/ratelimit/host/key.rs b/lychee-lib/src/ratelimit/host/key.rs index 4361b9b8da..aae34e5445 100644 --- a/lychee-lib/src/ratelimit/host/key.rs +++ b/lychee-lib/src/ratelimit/host/key.rs @@ -2,9 +2,6 @@ use serde::Deserialize; use std::fmt; use url::Url; -use crate::ErrorKind; -use crate::types::Result; - /// A type-safe representation of a hostname for rate limiting purposes. /// /// This extracts and normalizes hostnames from URLs to ensure consistent @@ -37,30 +34,24 @@ impl HostKey { } } -impl TryFrom<&Url> for HostKey { - type Error = ErrorKind; - - fn try_from(url: &Url) -> Result { - let host = url.host_str().ok_or_else(|| ErrorKind::InvalidUrlHost)?; +impl From<&Url> for HostKey { + fn from(url: &Url) -> Self { + let host = url.host_str().unwrap_or("unknown-host.internal"); // Normalize to lowercase for consistent lookup - Ok(HostKey(host.to_lowercase())) + HostKey(host.to_lowercase()) } } -impl TryFrom<&crate::Uri> for HostKey { - type Error = ErrorKind; - - fn try_from(uri: &crate::Uri) -> Result { - Self::try_from(&uri.url) +impl From<&crate::Uri> for HostKey { + fn from(uri: &crate::Uri) -> Self { + Self::from(&uri.url) } } -impl TryFrom for HostKey { - type Error = ErrorKind; - - fn try_from(url: Url) -> Result { - HostKey::try_from(&url) +impl From for HostKey { + fn from(url: Url) -> Self { + Self::from(&url) } } diff --git a/lychee-lib/src/ratelimit/pool.rs b/lychee-lib/src/ratelimit/pool.rs index a7357b5ece..eaedc4801c 100644 --- a/lychee-lib/src/ratelimit/pool.rs +++ b/lychee-lib/src/ratelimit/pool.rs @@ -69,7 +69,7 @@ impl HostPool { /// - The underlying HTTP request fails pub(crate) async fn execute_request(&self, request: Request) -> Result { let url = request.url(); - let host_key = HostKey::try_from(url)?; + let host_key = HostKey::from(url); let host = self.get_or_create_host(host_key); host.execute_request(request).await } @@ -82,7 +82,7 @@ impl HostPool { /// - The request URI has no valid hostname /// - The request fails to build pub fn build_request(&self, method: Method, uri: &Uri) -> Result { - let host_key = HostKey::try_from(uri)?; + let host_key = HostKey::from(uri); let host = self.get_or_create_host(host_key); host.get_client() .request(method, uri.url.clone()) @@ -195,15 +195,9 @@ impl HostPool { /// since this is handled internally. pub fn record_persistent_cache_hit(&self, uri: &crate::Uri) { if !uri.is_file() && !uri.is_mail() { - match crate::ratelimit::HostKey::try_from(uri) { - Ok(key) => { - let host = self.get_or_create_host(key); - host.record_persistent_cache_hit(); - } - Err(e) => { - log::debug!("Failed to record cache hit for {uri}: {e}"); - } - } + let key = crate::ratelimit::HostKey::from(uri); + let host = self.get_or_create_host(key); + host.record_persistent_cache_hit(); } } } diff --git a/lychee-lib/src/types/status.rs b/lychee-lib/src/types/status.rs index 35577ec4f3..d080df5e7e 100644 --- a/lychee-lib/src/types/status.rs +++ b/lychee-lib/src/types/status.rs @@ -298,7 +298,10 @@ impl Status { impl From for Status { fn from(e: ErrorKind) -> Self { - Self::Error(e) + match e { + ErrorKind::BuildRequestClient(e) => Status::from(e), + _ => Self::Error(e), + } } }