diff --git a/config/defaults.hjson b/config/defaults.hjson index 003adf11a7..14c1dce0bd 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -111,4 +111,6 @@ slur_filter: "(\bThis\b)|(\bis\b)|(\bsample\b)" # Maximum length of local community and user names actor_name_max_length: 20 + # Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search). + http_fetch_retry_limit: 25 } diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 93986a50f8..b44030b06f 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -81,6 +81,11 @@ where ); debug!("Fetching webfinger url: {}", &fetch_url); + *request_counter += 1; + if *request_counter > context.settings().http_fetch_retry_limit { + return Err(LemmyError::from(anyhow!("Request retry limit reached"))); + } + let response = retry(|| context.client().get(&fetch_url).send()).await?; let res: WebfingerResponse = response diff --git a/crates/apub_lib/src/object_id.rs b/crates/apub_lib/src/object_id.rs index 59898e6691..e8d0bd6d2a 100644 --- a/crates/apub_lib/src/object_id.rs +++ b/crates/apub_lib/src/object_id.rs @@ -18,10 +18,6 @@ use std::{ use tracing::info; use url::Url; -/// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object -/// fetch through the search). This should be configurable. -static REQUEST_LIMIT: i32 = 25; - static CLIENT: Lazy = Lazy::new(|| { Client::builder() .user_agent(build_user_agent(&Settings::get())) @@ -119,8 +115,8 @@ where info!("Fetching remote object {}", self.to_string()); *request_counter += 1; - if *request_counter > REQUEST_LIMIT { - return Err(LemmyError::from(anyhow!("Request limit reached"))); + if *request_counter > Settings::get().http_fetch_retry_limit { + return Err(LemmyError::from(anyhow!("Request retry limit reached"))); } let res = retry(|| { diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index c2434f86b4..88680c0806 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -58,7 +58,7 @@ pub struct SiteMetadata { /// Fetches the post link html tags (like title, description, image, etc) pub async fn fetch_site_metadata(client: &Client, url: &Url) -> Result { - let response = retry(|| client.get(url.as_str()).send()).await?; + let response = client.get(url.as_str()).send().await?; let html = response .text() @@ -132,7 +132,7 @@ pub(crate) async fn fetch_pictrs( utf8_percent_encode(image_url.as_str(), NON_ALPHANUMERIC) // TODO this might not be needed ); - let response = retry(|| client.get(&fetch_url).send()).await?; + let response = client.get(&fetch_url).send().await?; let response: PictrsResponse = response .json() @@ -201,8 +201,8 @@ pub async fn fetch_site_data( } } -async fn is_image_content_type(client: &Client, test: &Url) -> Result<(), LemmyError> { - let response = retry(|| client.get(test.to_owned()).send()).await?; +async fn is_image_content_type(client: &Client, url: &Url) -> Result<(), LemmyError> { + let response = client.get(url.as_str()).send().await?; if response .headers() .get("Content-Type") diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 1b8ac812ef..6a20386e7b 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -46,6 +46,9 @@ pub struct Settings { /// Maximum length of local community and user names #[default(20)] pub actor_name_max_length: usize, + /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search). + #[default(25)] + pub http_fetch_retry_limit: i32, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]