mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-11-22 09:31:07 +00:00
Send normal json accept header for normal json endpoints
This commit is contained in:
parent
0f95660aec
commit
c499b5355c
3 changed files with 18 additions and 4 deletions
|
@ -37,7 +37,7 @@ impl QueryInstance {
|
|||
|
||||
let instance = state
|
||||
.requests
|
||||
.fetch::<Instance>(instance_uri.as_str())
|
||||
.fetch_json::<Instance>(instance_uri.as_str())
|
||||
.await?;
|
||||
|
||||
let description = if instance.description.is_empty() {
|
||||
|
|
|
@ -26,7 +26,7 @@ impl QueryNodeinfo {
|
|||
|
||||
let well_known = state
|
||||
.requests
|
||||
.fetch::<WellKnown>(well_known_uri.as_str())
|
||||
.fetch_json::<WellKnown>(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::<Nodeinfo>(&href).await?;
|
||||
let nodeinfo = state.requests.fetch_json::<Nodeinfo>(&href).await?;
|
||||
|
||||
state
|
||||
.node_cache
|
||||
|
|
|
@ -56,7 +56,21 @@ impl Requests {
|
|||
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>
|
||||
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
|
||||
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(),
|
||||
|
|
Loading…
Reference in a new issue