Send normal json accept header for normal json endpoints

This commit is contained in:
asonix 2020-07-10 17:24:47 -05:00
parent 0f95660aec
commit c499b5355c
3 changed files with 18 additions and 4 deletions

View file

@ -37,7 +37,7 @@ impl QueryInstance {
let instance = state let instance = state
.requests .requests
.fetch::<Instance>(instance_uri.as_str()) .fetch_json::<Instance>(instance_uri.as_str())
.await?; .await?;
let description = if instance.description.is_empty() { let description = if instance.description.is_empty() {

View file

@ -26,7 +26,7 @@ impl QueryNodeinfo {
let well_known = state let well_known = state
.requests .requests
.fetch::<WellKnown>(well_known_uri.as_str()) .fetch_json::<WellKnown>(well_known_uri.as_str())
.await?; .await?;
let href = if let Some(link) = well_known.links.into_iter().find(|l| l.rel.is_supported()) { 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(()); return Ok(());
}; };
let nodeinfo = state.requests.fetch::<Nodeinfo>(&href).await?; let nodeinfo = state.requests.fetch_json::<Nodeinfo>(&href).await?;
state state
.node_cache .node_cache

View file

@ -56,7 +56,21 @@ impl Requests {
self.consecutive_errors.swap(0, Ordering::Relaxed); self.consecutive_errors.swap(0, Ordering::Relaxed);
} }
pub async fn fetch_json<T>(&self, url: &str) -> Result<T, MyError>
where
T: serde::de::DeserializeOwned,
{
self.do_fetch(url, "application/json").await
}
pub async fn fetch<T>(&self, url: &str) -> Result<T, MyError> pub async fn fetch<T>(&self, url: &str) -> Result<T, MyError>
where
T: serde::de::DeserializeOwned,
{
self.do_fetch(url, "application/activity+json").await
}
async fn do_fetch<T>(&self, url: &str, accept: &str) -> Result<T, MyError>
where where
T: serde::de::DeserializeOwned, T: serde::de::DeserializeOwned,
{ {
@ -65,7 +79,7 @@ impl Requests {
let client: Client = self.client.borrow().clone(); let client: Client = self.client.borrow().clone();
let res = client let res = client
.get(url) .get(url)
.header("Accept", "application/activity+json") .header("Accept", accept)
.set(Date(SystemTime::now().into())) .set(Date(SystemTime::now().into()))
.signature( .signature(
self.config.clone(), self.config.clone(),