1 use crate::APUB_JSON_CONTENT_TYPE;
4 use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError, REQWEST_TIMEOUT};
5 use reqwest_middleware::ClientWithMiddleware;
6 use serde::de::DeserializeOwned;
7 use tracing::log::info;
10 pub async fn fetch_object_http<Kind: DeserializeOwned>(
12 client: &ClientWithMiddleware,
13 request_counter: &mut i32,
14 ) -> Result<Kind, LemmyError> {
15 // dont fetch local objects this way
16 debug_assert!(url.domain() != Some(&Settings::get().hostname));
17 info!("Fetching remote object {}", url.to_string());
19 *request_counter += 1;
20 if *request_counter > Settings::get().http_fetch_retry_limit {
21 return Err(LemmyError::from(anyhow!("Request retry limit reached")));
27 .header("Accept", APUB_JSON_CONTENT_TYPE)
28 .timeout(REQWEST_TIMEOUT)
33 if res.status() == StatusCode::GONE {
34 return Err(LemmyError::from_message("410"));