Move federation client builders to activitypub::http_client module
This commit is contained in:
parent
f17c9d9f76
commit
0817177282
4 changed files with 41 additions and 29 deletions
|
@ -1,8 +1,7 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use actix_web::http::Method;
|
||||
use reqwest::{Client, Proxy};
|
||||
use reqwest::Client;
|
||||
use rsa::RsaPrivateKey;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
@ -24,10 +23,13 @@ use crate::json_signatures::create::{
|
|||
JsonSignatureError,
|
||||
};
|
||||
use crate::models::users::types::User;
|
||||
use super::actors::types::Actor;
|
||||
use super::constants::AP_MEDIA_TYPE;
|
||||
use super::identifiers::{local_actor_id, local_actor_key_id};
|
||||
use super::queues::OutgoingActivityJobData;
|
||||
use super::{
|
||||
actors::types::Actor,
|
||||
constants::AP_MEDIA_TYPE,
|
||||
http_client::build_federation_client,
|
||||
identifiers::{local_actor_id, local_actor_key_id},
|
||||
queues::OutgoingActivityJobData,
|
||||
};
|
||||
|
||||
const DELIVERER_TIMEOUT: u64 = 30;
|
||||
|
||||
|
@ -56,15 +58,7 @@ pub enum DelivererError {
|
|||
}
|
||||
|
||||
fn build_client(instance: &Instance) -> reqwest::Result<Client> {
|
||||
let mut client_builder = Client::builder();
|
||||
if let Some(ref proxy_url) = instance.proxy_url {
|
||||
let proxy = Proxy::all(proxy_url)?;
|
||||
client_builder = client_builder.proxy(proxy);
|
||||
};
|
||||
let timeout = Duration::from_secs(DELIVERER_TIMEOUT);
|
||||
client_builder
|
||||
.timeout(timeout)
|
||||
.build()
|
||||
build_federation_client(instance, DELIVERER_TIMEOUT)
|
||||
}
|
||||
|
||||
async fn send_activity(
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
use reqwest::{Client, Method, Proxy, RequestBuilder};
|
||||
use reqwest::{Client, Method, RequestBuilder};
|
||||
use serde_json::Value;
|
||||
|
||||
use mitra_config::Instance;
|
||||
|
@ -13,6 +12,7 @@ use mitra_utils::{
|
|||
use crate::activitypub::{
|
||||
actors::types::Actor,
|
||||
constants::{AP_CONTEXT, AP_MEDIA_TYPE},
|
||||
http_client::build_federation_client,
|
||||
identifiers::{local_actor_key_id, local_instance_actor_id},
|
||||
types::Object,
|
||||
vocabulary::GROUP,
|
||||
|
@ -24,7 +24,6 @@ use crate::http_signatures::create::{
|
|||
use crate::media::{save_file, SUPPORTED_MEDIA_TYPES};
|
||||
use crate::webfinger::types::{ActorAddress, JsonResourceDescriptor};
|
||||
|
||||
const FETCHER_CONNECTION_TIMEOUT: u64 = 30;
|
||||
const FETCHER_TIMEOUT: u64 = 180;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
@ -52,17 +51,7 @@ pub enum FetchError {
|
|||
}
|
||||
|
||||
fn build_client(instance: &Instance) -> reqwest::Result<Client> {
|
||||
let mut client_builder = Client::builder();
|
||||
if let Some(ref proxy_url) = instance.proxy_url {
|
||||
let proxy = Proxy::all(proxy_url)?;
|
||||
client_builder = client_builder.proxy(proxy);
|
||||
};
|
||||
let timeout = Duration::from_secs(FETCHER_TIMEOUT);
|
||||
let connect_timeout = Duration::from_secs(FETCHER_CONNECTION_TIMEOUT);
|
||||
client_builder
|
||||
.timeout(timeout)
|
||||
.connect_timeout(connect_timeout)
|
||||
.build()
|
||||
build_federation_client(instance, FETCHER_TIMEOUT)
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
|
|
28
src/activitypub/http_client.rs
Normal file
28
src/activitypub/http_client.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use std::cmp::max;
|
||||
use std::time::Duration;
|
||||
|
||||
use reqwest::{Client, Proxy};
|
||||
|
||||
use mitra_config::Instance;
|
||||
|
||||
const CONNECTION_TIMEOUT: u64 = 30;
|
||||
|
||||
pub fn build_federation_client(
|
||||
instance: &Instance,
|
||||
timeout: u64,
|
||||
) -> reqwest::Result<Client> {
|
||||
let mut client_builder = Client::builder();
|
||||
if let Some(ref proxy_url) = instance.proxy_url {
|
||||
let proxy = Proxy::all(proxy_url)?;
|
||||
client_builder = client_builder.proxy(proxy);
|
||||
};
|
||||
let request_timeout = Duration::from_secs(timeout);
|
||||
let connect_timeout = Duration::from_secs(max(
|
||||
timeout,
|
||||
CONNECTION_TIMEOUT,
|
||||
));
|
||||
client_builder
|
||||
.timeout(request_timeout)
|
||||
.connect_timeout(connect_timeout)
|
||||
.build()
|
||||
}
|
|
@ -6,6 +6,7 @@ pub mod constants;
|
|||
mod deliverer;
|
||||
pub mod fetcher;
|
||||
mod handlers;
|
||||
mod http_client;
|
||||
pub mod identifiers;
|
||||
pub mod queues;
|
||||
mod receiver;
|
||||
|
|
Loading…
Reference in a new issue