From c499b5355c4a94a28a1eff03bc1917d57fd96a1a Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 10 Jul 2020 17:24:47 -0500 Subject: [PATCH] Send normal json accept header for normal json endpoints --- src/jobs/instance.rs | 2 +- src/jobs/nodeinfo.rs | 4 ++-- src/requests.rs | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/jobs/instance.rs b/src/jobs/instance.rs index b483417..25a5491 100644 --- a/src/jobs/instance.rs +++ b/src/jobs/instance.rs @@ -37,7 +37,7 @@ impl QueryInstance { let instance = state .requests - .fetch::(instance_uri.as_str()) + .fetch_json::(instance_uri.as_str()) .await?; let description = if instance.description.is_empty() { diff --git a/src/jobs/nodeinfo.rs b/src/jobs/nodeinfo.rs index b5a5a30..661a793 100644 --- a/src/jobs/nodeinfo.rs +++ b/src/jobs/nodeinfo.rs @@ -26,7 +26,7 @@ impl QueryNodeinfo { let well_known = state .requests - .fetch::(well_known_uri.as_str()) + .fetch_json::(well_known_uri.as_str()) .await?; let href = if let Some(link) = well_known.links.into_iter().find(|l| l.rel.is_supported()) { @@ -35,7 +35,7 @@ impl QueryNodeinfo { return Ok(()); }; - let nodeinfo = state.requests.fetch::(&href).await?; + let nodeinfo = state.requests.fetch_json::(&href).await?; state .node_cache diff --git a/src/requests.rs b/src/requests.rs index b87ecdd..24eabd3 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -56,7 +56,21 @@ impl Requests { self.consecutive_errors.swap(0, Ordering::Relaxed); } + pub async fn fetch_json(&self, url: &str) -> Result + where + T: serde::de::DeserializeOwned, + { + self.do_fetch(url, "application/json").await + } + pub async fn fetch(&self, url: &str) -> Result + where + T: serde::de::DeserializeOwned, + { + self.do_fetch(url, "application/activity+json").await + } + + async fn do_fetch(&self, url: &str, accept: &str) -> Result where T: serde::de::DeserializeOwned, { @@ -65,7 +79,7 @@ impl Requests { let client: Client = self.client.borrow().clone(); let res = client .get(url) - .header("Accept", "application/activity+json") + .header("Accept", accept) .set(Date(SystemTime::now().into())) .signature( self.config.clone(),