diff --git a/plume-common/src/activity_pub/request.rs b/plume-common/src/activity_pub/request.rs index c2a523e4..4258bd7b 100644 --- a/plume-common/src/activity_pub/request.rs +++ b/plume-common/src/activity_pub/request.rs @@ -1,8 +1,10 @@ use chrono::{offset::Utc, DateTime}; use openssl::hash::{Hasher, MessageDigest}; use reqwest::{ - header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, HOST, USER_AGENT}, - ClientBuilder, Proxy, Response, Url, + header::{ + HeaderMap, HeaderValue, InvalidHeaderValue, ACCEPT, CONTENT_TYPE, DATE, HOST, USER_AGENT, + }, + ClientBuilder, Proxy, Response, Url, UrlError, }; use std::ops::Deref; use std::time::SystemTime; @@ -16,6 +18,24 @@ const PLUME_USER_AGENT: &str = concat!("Plume/", env!("CARGO_PKG_VERSION")); #[derive(Debug)] pub struct Error(); +impl From for Error { + fn from(_err: UrlError) -> Self { + Error() + } +} + +impl From for Error { + fn from(_err: InvalidHeaderValue) -> Self { + Error() + } +} + +impl From for Error { + fn from(_err: reqwest::Error) -> Self { + Error() + } +} + pub struct Digest(String); impl Digest { @@ -169,12 +189,11 @@ pub fn signature( pub fn get(url_str: &str, sender: &dyn Signer, proxy: Option) -> Result { let mut headers = headers(); - let url = Url::parse(url_str).map_err(|_| Error())?; // TODO: Define and use From trait + let url = Url::parse(url_str)?; if !url.has_host() { return Err(Error()); } - let host_header_value = - HeaderValue::from_str(url.host_str().expect("Unreachable")).map_err(|_| Error())?; + let host_header_value = HeaderValue::from_str(url.host_str().expect("Unreachable"))?; headers.insert(HOST, host_header_value); if let Some(proxy) = proxy { ClientBuilder::new().proxy(proxy) @@ -182,13 +201,12 @@ pub fn get(url_str: &str, sender: &dyn Signer, proxy: Option) -> Result