Set accept header and timeout for outgoing apub requests
This commit is contained in:
parent
4fadc4d072
commit
17bf6baa25
2 changed files with 12 additions and 2 deletions
|
@ -13,12 +13,14 @@ use url::Url;
|
||||||
|
|
||||||
type GroupExt = Ext<Group, ApActorProperties>;
|
type GroupExt = Ext<Group, ApActorProperties>;
|
||||||
|
|
||||||
|
static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
|
||||||
|
|
||||||
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
|
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
|
||||||
where
|
where
|
||||||
T: serde::ser::Serialize,
|
T: serde::ser::Serialize,
|
||||||
{
|
{
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("application/activity+json")
|
.content_type(APUB_JSON_CONTENT_TYPE)
|
||||||
.json(json)
|
.json(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ use failure::Error;
|
||||||
use isahc::prelude::*;
|
use isahc::prelude::*;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
fn fetch_node_info(domain: &str) -> Result<NodeInfo, Error> {
|
fn fetch_node_info(domain: &str) -> Result<NodeInfo, Error> {
|
||||||
let well_known_uri = format!(
|
let well_known_uri = format!(
|
||||||
|
@ -56,7 +57,14 @@ where
|
||||||
}
|
}
|
||||||
// TODO: should cache responses here when we are in production
|
// TODO: should cache responses here when we are in production
|
||||||
// TODO: this function should return a future
|
// TODO: this function should return a future
|
||||||
let text = isahc::get(uri)?.text()?;
|
let timeout = Duration::from_secs(60);
|
||||||
|
let text = Request::get(uri)
|
||||||
|
.header("Accept", APUB_JSON_CONTENT_TYPE)
|
||||||
|
.connect_timeout(timeout)
|
||||||
|
.timeout(timeout)
|
||||||
|
.body(())?
|
||||||
|
.send()?
|
||||||
|
.text()?;
|
||||||
let res: Response = serde_json::from_str(&text)?;
|
let res: Response = serde_json::from_str(&text)?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue