mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
parent
83e996111e
commit
1e9f609cdb
6 changed files with 18 additions and 17 deletions
|
@ -2,14 +2,13 @@ use crate::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use chrono::{Duration as ChronoDuration, NaiveDateTime, Utc};
|
use chrono::{Duration as ChronoDuration, NaiveDateTime, Utc};
|
||||||
use diesel::NotFound;
|
use diesel::NotFound;
|
||||||
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
|
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError, REQWEST_TIMEOUT};
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Debug, Display, Formatter},
|
fmt::{Debug, Display, Formatter},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -114,7 +113,7 @@ where
|
||||||
client
|
client
|
||||||
.get(self.0.as_str())
|
.get(self.0.as_str())
|
||||||
.header("Accept", APUB_JSON_CONTENT_TYPE)
|
.header("Accept", APUB_JSON_CONTENT_TYPE)
|
||||||
.timeout(Duration::from_secs(60))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.send()
|
.send()
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use anyhow::anyhow;
|
||||||
use http::{header::HeaderName, HeaderMap, HeaderValue};
|
use http::{header::HeaderName, HeaderMap, HeaderValue};
|
||||||
use http_signature_normalization_actix::Config as ConfigActix;
|
use http_signature_normalization_actix::Config as ConfigActix;
|
||||||
use http_signature_normalization_reqwest::prelude::{Config, SignExt};
|
use http_signature_normalization_reqwest::prelude::{Config, SignExt};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::{LemmyError, REQWEST_TIMEOUT};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use openssl::{
|
use openssl::{
|
||||||
hash::MessageDigest,
|
hash::MessageDigest,
|
||||||
|
@ -15,7 +15,7 @@ use reqwest::Response;
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::str::FromStr;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub async fn sign_and_send(
|
||||||
let request = client
|
let request = client
|
||||||
.post(&inbox_url.to_string())
|
.post(&inbox_url.to_string())
|
||||||
// signature is only valid for 10 seconds, so no reason to wait any longer
|
// signature is only valid for 10 seconds, so no reason to wait any longer
|
||||||
.timeout(Duration::from_secs(10))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.signature_with_digest(
|
.signature_with_digest(
|
||||||
HTTP_SIG_CONFIG.clone(),
|
HTTP_SIG_CONFIG.clone(),
|
||||||
|
|
|
@ -12,12 +12,11 @@ use actix_web::{
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use futures::stream::{Stream, StreamExt};
|
use futures::stream::{Stream, StreamExt};
|
||||||
use lemmy_utils::{claims::Claims, rate_limit::RateLimit, LemmyError};
|
use lemmy_utils::{claims::Claims, rate_limit::RateLimit, LemmyError, REQWEST_TIMEOUT};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use reqwest::Body;
|
use reqwest::Body;
|
||||||
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig, client: ClientWithMiddleware, rate_limit: &RateLimit) {
|
pub fn config(cfg: &mut web::ServiceConfig, client: ClientWithMiddleware, rate_limit: &RateLimit) {
|
||||||
cfg
|
cfg
|
||||||
|
@ -60,7 +59,7 @@ fn adapt_request(
|
||||||
|
|
||||||
let client_request = client
|
let client_request = client
|
||||||
.request(request.method().clone(), url)
|
.request(request.method().clone(), url)
|
||||||
.timeout(Duration::from_secs(30));
|
.timeout(REQWEST_TIMEOUT);
|
||||||
|
|
||||||
request
|
request
|
||||||
.headers()
|
.headers()
|
||||||
|
|
|
@ -21,11 +21,13 @@ pub use sensitive::Sensitive;
|
||||||
|
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use std::{fmt, fmt::Display};
|
use std::{fmt, fmt::Display, time::Duration};
|
||||||
use tracing_error::SpanTrace;
|
use tracing_error::SpanTrace;
|
||||||
|
|
||||||
pub type ConnectionId = usize;
|
pub type ConnectionId = usize;
|
||||||
|
|
||||||
|
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
||||||
pub struct IpAddr(pub String);
|
pub struct IpAddr(pub String);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{settings::structs::Settings, version::VERSION, LemmyError};
|
use crate::{settings::structs::Settings, version::VERSION, LemmyError, REQWEST_TIMEOUT};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use encoding::{all::encodings, DecoderTrap};
|
use encoding::{all::encodings, DecoderTrap};
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{future::Future, time::Duration};
|
use std::future::Future;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -71,7 +71,7 @@ pub async fn fetch_site_metadata(
|
||||||
info!("Fetching site metadata for url: {}", url);
|
info!("Fetching site metadata for url: {}", url);
|
||||||
let response = client
|
let response = client
|
||||||
.get(url.as_str())
|
.get(url.as_str())
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ pub(crate) async fn fetch_pictrs(
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(&fetch_url)
|
.get(&fetch_url)
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ pub async fn fetch_site_data(
|
||||||
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> {
|
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> {
|
||||||
let response = client
|
let response = client
|
||||||
.get(url.as_str())
|
.get(url.as_str())
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
if response
|
if response
|
||||||
|
|
|
@ -26,12 +26,13 @@ use lemmy_utils::{
|
||||||
request::build_user_agent,
|
request::build_user_agent,
|
||||||
settings::structs::Settings,
|
settings::structs::Settings,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
|
REQWEST_TIMEOUT,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use reqwest_middleware::ClientBuilder;
|
use reqwest_middleware::ClientBuilder;
|
||||||
use reqwest_tracing::TracingMiddleware;
|
use reqwest_tracing::TracingMiddleware;
|
||||||
use std::{env, sync::Arc, thread, time::Duration};
|
use std::{env, sync::Arc, thread};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tracing_actix_web::TracingLogger;
|
use tracing_actix_web::TracingLogger;
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ async fn main() -> Result<(), LemmyError> {
|
||||||
|
|
||||||
let client = Client::builder()
|
let client = Client::builder()
|
||||||
.user_agent(build_user_agent(&settings))
|
.user_agent(build_user_agent(&settings))
|
||||||
.timeout(Duration::from_secs(10))
|
.timeout(REQWEST_TIMEOUT)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let client = ClientBuilder::new(client).with(TracingMiddleware).build();
|
let client = ClientBuilder::new(client).with(TracingMiddleware).build();
|
||||||
|
|
Loading…
Reference in a new issue