This commit is contained in:
Felix Ableitner 2023-10-20 15:11:31 +02:00
parent 9184800582
commit 93b96c7af5
3 changed files with 14 additions and 20 deletions

View file

@ -290,17 +290,16 @@ async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Resu
}
pub fn client_builder(settings: &Settings) -> ClientBuilder {
let user_agent =
format!(
"Lemmy/{}; +{}",
VERSION,
settings.get_protocol_and_hostname()
);
let user_agent = format!(
"Lemmy/{}; +{}",
VERSION,
settings.get_protocol_and_hostname()
);
Client::builder()
.user_agent(user_agent.clone())
.timeout(REQWEST_TIMEOUT)
.connect_timeout(REQWEST_TIMEOUT)
.user_agent(user_agent.clone())
.timeout(REQWEST_TIMEOUT)
.connect_timeout(REQWEST_TIMEOUT)
}
#[cfg(test)]
@ -316,9 +315,7 @@ mod tests {
#[tokio::test]
async fn test_site_metadata() {
let settings = &SETTINGS.clone();
let client = client_builder(settings).build()
.unwrap()
.into();
let client = client_builder(settings).build().unwrap().into();
let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ").unwrap();
let sample_res = fetch_site_metadata(&client, &sample_url).await.unwrap();
assert_eq!(

View file

@ -59,13 +59,12 @@ pub(crate) mod tests {
use activitypub_federation::config::{Data, FederationConfig};
use anyhow::anyhow;
use lemmy_api_common::{context::LemmyContext};
use lemmy_api_common::{context::LemmyContext, request::client_builder};
use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool_for_tests};
use lemmy_utils::{rate_limit::RateLimitCell, settings::SETTINGS};
use reqwest::{Request, Response};
use reqwest_middleware::{ClientBuilder, Middleware, Next};
use task_local_extensions::Extensions;
use lemmy_api_common::request::client_builder;
struct BlockedMiddleware;
@ -87,9 +86,7 @@ pub(crate) mod tests {
// call this to run migrations
let pool = build_db_pool_for_tests().await;
let client = client_builder(&SETTINGS)
.build()
.unwrap();
let client = client_builder(&SETTINGS).build().unwrap();
let client = ClientBuilder::new(client).with(BlockedMiddleware).build();
let secret = Secret {

View file

@ -28,6 +28,7 @@ use clap::{ArgAction, Parser};
use lemmy_api_common::{
context::LemmyContext,
lemmy_db_views::structs::SiteView,
request::client_builder,
send_activity::{ActivityChannel, MATCH_OUTGOING_ACTIVITIES},
utils::{
check_private_instance_and_federation_enabled,
@ -68,7 +69,6 @@ use {
prometheus::default_registry,
prometheus_metrics::serve_prometheus,
};
use lemmy_api_common::request::client_builder;
#[derive(Parser, Debug)]
#[command(
@ -202,8 +202,8 @@ pub async fn start_lemmy_server(args: CmdArgs) -> Result<(), LemmyError> {
// Pictrs cannot use proxy
let pictrs_client = ClientBuilder::new(client_builder(&SETTINGS).no_proxy().build()?)
.with(TracingMiddleware::default())
.build();
.with(TracingMiddleware::default())
.build();
Some(create_http_server(
federation_config.clone(),
SETTINGS.clone(),