From: Felix Ableitner Date: Tue, 7 Apr 2020 15:29:23 +0000 (+0200) Subject: Set accept header and timeout for outgoing apub requests X-Git-Url: http://these/git/%7B%60https:/static/%24%7Bsubmission.url%7D?a=commitdiff_plain;h=17bf6baa25a7b98718f209710d8a8ed908d125bd;p=lemmy.git Set accept header and timeout for outgoing apub requests --- diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index f2e5a56f..1669ee89 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -13,12 +13,14 @@ use url::Url; type GroupExt = Ext; +static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; + fn create_apub_response(json: &T) -> HttpResponse where T: serde::ser::Serialize, { HttpResponse::Ok() - .content_type("application/activity+json") + .content_type(APUB_JSON_CONTENT_TYPE) .json(json) } diff --git a/server/src/apub/puller.rs b/server/src/apub/puller.rs index 915f1884..fde914bc 100644 --- a/server/src/apub/puller.rs +++ b/server/src/apub/puller.rs @@ -12,6 +12,7 @@ use failure::Error; use isahc::prelude::*; use log::warn; use serde::Deserialize; +use std::time::Duration; fn fetch_node_info(domain: &str) -> Result { let well_known_uri = format!( @@ -56,7 +57,14 @@ where } // TODO: should cache responses here when we are in production // 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)?; Ok(res) }