mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-09 09:52:10 +00:00
Add separate pictrs reqwest client.
This commit is contained in:
parent
3456da12a4
commit
c57c5cb864
|
@ -11,7 +11,7 @@ use actix_web::{
|
|||
HttpResponse,
|
||||
};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use lemmy_utils::{claims::Claims, rate_limit::RateLimit};
|
||||
use lemmy_utils::{claims::Claims, rate_limit::RateLimit, REQWEST_TIMEOUT};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use reqwest::Body;
|
||||
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
||||
|
@ -65,7 +65,9 @@ fn adapt_request(
|
|||
// remove accept-encoding header so that pictrs doesnt compress the response
|
||||
const INVALID_HEADERS: &[HeaderName] = &[ACCEPT_ENCODING, HOST];
|
||||
|
||||
let client_request = client.request(request.method().clone(), url);
|
||||
let client_request = client
|
||||
.request(request.method().clone(), url)
|
||||
.timeout(REQWEST_TIMEOUT);
|
||||
|
||||
request
|
||||
.headers()
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -99,7 +99,7 @@ async fn main() -> Result<(), LemmyError> {
|
|||
settings.bind, settings.port
|
||||
);
|
||||
|
||||
let client = Client::builder()
|
||||
let reqwest_client = Client::builder()
|
||||
.user_agent(build_user_agent(&settings))
|
||||
.timeout(REQWEST_TIMEOUT)
|
||||
.build()?;
|
||||
|
@ -111,11 +111,16 @@ async fn main() -> Result<(), LemmyError> {
|
|||
backoff_exponent: 2,
|
||||
};
|
||||
|
||||
let client = ClientBuilder::new(client)
|
||||
let client = ClientBuilder::new(reqwest_client.clone())
|
||||
.with(TracingMiddleware)
|
||||
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
|
||||
.build();
|
||||
|
||||
// Pictrs cannot use the retry middleware
|
||||
let pictrs_client = ClientBuilder::new(reqwest_client.clone())
|
||||
.with(TracingMiddleware)
|
||||
.build();
|
||||
|
||||
check_private_instance_and_federation_enabled(&pool, &settings).await?;
|
||||
|
||||
let chat_server = ChatServer::startup(
|
||||
|
@ -149,7 +154,7 @@ async fn main() -> Result<(), LemmyError> {
|
|||
.configure(|cfg| api_routes::config(cfg, &rate_limiter))
|
||||
.configure(|cfg| lemmy_apub::http::routes::config(cfg, &settings))
|
||||
.configure(feeds::config)
|
||||
.configure(|cfg| images::config(cfg, client.clone(), &rate_limiter))
|
||||
.configure(|cfg| images::config(cfg, pictrs_client.clone(), &rate_limiter))
|
||||
.configure(nodeinfo::config)
|
||||
.configure(|cfg| webfinger::config(cfg, &settings))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue