mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-01 20:20:32 +00:00
Fix build errors; cleanup code
This commit is contained in:
parent
00ddb6dfc8
commit
b2ce61357f
4 changed files with 16 additions and 18 deletions
|
|
@ -93,7 +93,7 @@ pub struct ClientBuilder {
|
|||
accepted: Option<HashSet<StatusCode>>,
|
||||
/// Response timeout per request
|
||||
timeout: Option<Duration>,
|
||||
/// Treat HTTP links as erros when HTTPS is available
|
||||
/// Treat HTTP links as errors when HTTPS is available
|
||||
require_https: bool,
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ impl Client {
|
|||
}
|
||||
|
||||
pub async fn check_file(&self, uri: &Uri) -> Status {
|
||||
if let Ok(path) = uri.inner.to_file_path() {
|
||||
if let Ok(path) = uri.url.to_file_path() {
|
||||
if path.exists() {
|
||||
return Status::Ok(StatusCode::OK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,15 @@ pub(crate) fn extract_links(
|
|||
for link in links {
|
||||
let req = if let Ok(uri) = Uri::try_from(link.as_str()) {
|
||||
Request::new(uri, input_content.input.clone())
|
||||
} else if let Some(new_url) = base.as_ref().and_then(|u| u.join(&link)) {
|
||||
Request::new(Uri { inner: new_url }, input_content.input.clone())
|
||||
} else if let Some(url) = base.as_ref().and_then(|u| u.join(&link)) {
|
||||
Request::new(Uri { url }, input_content.input.clone())
|
||||
} else if let Input::FsPath(root) = &input_content.input {
|
||||
if url::is_anchor(&link) {
|
||||
// Silently ignore anchor links for now
|
||||
continue;
|
||||
}
|
||||
let uri = create_uri_from_path(root, base, &link)?;
|
||||
Request::new(Uri { inner: uri }, input_content.input.clone())
|
||||
let url = create_uri_from_path(root, base, &link)?;
|
||||
Request::new(Uri { url }, input_content.input.clone())
|
||||
} else {
|
||||
info!("Handling of {} not implemented yet", &link);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -74,11 +74,10 @@ impl Hash for ErrorKind {
|
|||
Self::HubcapsError(e) => e.to_string().hash(state),
|
||||
Self::FileNotFound(e) => e.to_string_lossy().hash(state),
|
||||
Self::UrlParseError(s, e) => (s, e.type_id()).hash(state),
|
||||
Self::UnreachableEmailAddress(u) | Self::InsecureURL(u) => u.hash(state),
|
||||
Self::InvalidFileUri(u) => u.hash(state),
|
||||
Self::InvalidFileUri(f) => f.hash(state),
|
||||
Self::InvalidPath(p) => p.hash(state),
|
||||
Self::UnreachableEmailAddress(u) => u.hash(state),
|
||||
Self::UnreachableEmailAddress(u) | Self::InsecureURL(u) => u.hash(state),
|
||||
Self::InvalidBase(base, e) => (base, e).hash(state),
|
||||
Self::InvalidHeader(e) => e.to_string().hash(state),
|
||||
Self::InvalidGlobPattern(e) => e.to_string().hash(state),
|
||||
Self::MissingGitHubToken => std::mem::discriminant(self).hash(state),
|
||||
|
|
@ -123,7 +122,6 @@ impl Display for ErrorKind {
|
|||
"This URL is available in HTTPS protocol, but HTTP is provided, use '{}' instead",
|
||||
uri
|
||||
),
|
||||
Self::InvalidBase(base, e) => write!(f, "Error while base dir `{}` : {}", base, e),
|
||||
Self::InvalidBase(base, e) => write!(f, "Error with base dir `{}` : {}", base, e),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ use url::Url;
|
|||
|
||||
use crate::{ErrorKind, Result};
|
||||
|
||||
/// Lychee's own representation of a URI, which encapsulates all supported formats.
|
||||
/// Lychee's own representation of a URI, which encapsulates all support formats.
|
||||
///
|
||||
/// If the scheme is `mailto`, it's a mail address.
|
||||
/// Otherwise it's treated as a website URL.
|
||||
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Uri {
|
||||
/// Website URL or mail address
|
||||
pub(crate) inner: Url,
|
||||
pub(crate) url: Url,
|
||||
}
|
||||
|
||||
impl Uri {
|
||||
|
|
@ -24,21 +24,21 @@ impl Uri {
|
|||
#[inline]
|
||||
#[must_use]
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.inner.as_ref().trim_start_matches("mailto:")
|
||||
self.url.as_ref().trim_start_matches("mailto:")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Returns the scheme of the URI (e.g. `http` or `mailto`)
|
||||
pub fn scheme(&self) -> &str {
|
||||
self.inner.scheme()
|
||||
self.url.scheme()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Returns the domain of the URI (e.g. `example.org`)
|
||||
pub fn domain(&self) -> Option<&str> {
|
||||
self.inner.domain()
|
||||
self.url.domain()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -49,14 +49,14 @@ impl Uri {
|
|||
///
|
||||
/// Return `None` for cannot-be-a-base URLs.
|
||||
pub fn path_segments(&self) -> Option<std::str::Split<char>> {
|
||||
self.inner.path_segments()
|
||||
self.url.path_segments()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Returns the IP address (either IPv4 or IPv6) of the URI,
|
||||
/// or `None` if it is a domain
|
||||
pub fn host_ip(&self) -> Option<IpAddr> {
|
||||
match self.inner.host()? {
|
||||
match self.url.host()? {
|
||||
url::Host::Domain(_) => None,
|
||||
url::Host::Ipv4(v4_addr) => Some(v4_addr.into()),
|
||||
url::Host::Ipv6(v6_addr) => Some(v6_addr.into()),
|
||||
|
|
@ -100,7 +100,7 @@ impl AsRef<str> for Uri {
|
|||
|
||||
impl From<Url> for Uri {
|
||||
fn from(url: Url) -> Self {
|
||||
Self { inner: url }
|
||||
Self { url }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue