mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-19 12:40:10 +00:00
Rename reqwest clients, mention cheap client clones in comment
This commit is contained in:
parent
1059f35fdc
commit
b39ddf7be9
@ -46,7 +46,7 @@ where
|
|||||||
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
|
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
|
||||||
|
|
||||||
let url = reqwest_request.url().clone();
|
let url = reqwest_request.url().clone();
|
||||||
let mut response = globals.reqwest_client().execute(reqwest_request).await?;
|
let mut response = globals.default_client().execute(reqwest_request).await?;
|
||||||
|
|
||||||
// reqwest::Response -> http::Response conversion
|
// reqwest::Response -> http::Response conversion
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
|
@ -39,8 +39,8 @@ pub struct Globals {
|
|||||||
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
|
||||||
dns_resolver: TokioAsyncResolver,
|
dns_resolver: TokioAsyncResolver,
|
||||||
jwt_decoding_key: Option<jsonwebtoken::DecodingKey<'static>>,
|
jwt_decoding_key: Option<jsonwebtoken::DecodingKey<'static>>,
|
||||||
well_known_client: reqwest::Client,
|
federation_client: reqwest::Client,
|
||||||
basic_client: reqwest::Client,
|
default_client: reqwest::Client,
|
||||||
pub(super) server_signingkeys: Arc<dyn Tree>,
|
pub(super) server_signingkeys: Arc<dyn Tree>,
|
||||||
pub bad_event_ratelimiter: Arc<RwLock<HashMap<Box<EventId>, RateLimitState>>>,
|
pub bad_event_ratelimiter: Arc<RwLock<HashMap<Box<EventId>, RateLimitState>>>,
|
||||||
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
|
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
|
||||||
@ -134,9 +134,9 @@ impl Globals {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static());
|
.map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static());
|
||||||
|
|
||||||
let basic_client = reqwest_client_builder(&config)?.build()?;
|
let default_client = reqwest_client_builder(&config)?.build()?;
|
||||||
let name_override = Arc::clone(&tls_name_override);
|
let name_override = Arc::clone(&tls_name_override);
|
||||||
let well_known_client = reqwest_client_builder(&config)?
|
let federation_client = reqwest_client_builder(&config)?
|
||||||
.resolve_fn(move |domain| {
|
.resolve_fn(move |domain| {
|
||||||
let read_guard = name_override.read().unwrap();
|
let read_guard = name_override.read().unwrap();
|
||||||
let (override_name, port) = read_guard.get(&domain)?;
|
let (override_name, port) = read_guard.get(&domain)?;
|
||||||
@ -154,8 +154,8 @@ impl Globals {
|
|||||||
})?,
|
})?,
|
||||||
actual_destination_cache: Arc::new(RwLock::new(WellKnownMap::new())),
|
actual_destination_cache: Arc::new(RwLock::new(WellKnownMap::new())),
|
||||||
tls_name_override,
|
tls_name_override,
|
||||||
well_known_client,
|
federation_client,
|
||||||
basic_client,
|
default_client,
|
||||||
server_signingkeys,
|
server_signingkeys,
|
||||||
jwt_decoding_key,
|
jwt_decoding_key,
|
||||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||||
@ -179,15 +179,15 @@ impl Globals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reqwest client which can be used to send requests
|
/// Returns a reqwest client which can be used to send requests
|
||||||
pub fn reqwest_client(&self) -> reqwest::Client {
|
pub fn default_client(&self) -> reqwest::Client {
|
||||||
// can't return &Client or else we'll hold a lock around the DB across an await
|
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
|
||||||
self.basic_client.clone()
|
self.default_client.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a client used for resolving .well-knowns
|
/// Returns a client used for resolving .well-knowns
|
||||||
pub fn well_known_client(&self) -> reqwest::Client {
|
pub fn federation_client(&self) -> reqwest::Client {
|
||||||
// can't return &Client or else we'll hold a lock around the DB across an await
|
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
|
||||||
self.well_known_client.clone()
|
self.federation_client.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
|
@ -115,7 +115,7 @@ where
|
|||||||
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
||||||
|
|
||||||
let url = reqwest_request.url().clone();
|
let url = reqwest_request.url().clone();
|
||||||
let response = globals.reqwest_client().execute(reqwest_request).await;
|
let response = globals.default_client().execute(reqwest_request).await;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(mut response) => {
|
Ok(mut response) => {
|
||||||
|
@ -237,7 +237,7 @@ where
|
|||||||
|
|
||||||
let url = reqwest_request.url().clone();
|
let url = reqwest_request.url().clone();
|
||||||
|
|
||||||
let response = globals.well_known_client().execute(reqwest_request).await;
|
let response = globals.federation_client().execute(reqwest_request).await;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(mut response) => {
|
Ok(mut response) => {
|
||||||
@ -477,7 +477,7 @@ async fn request_well_known(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let body: serde_json::Value = serde_json::from_str(
|
let body: serde_json::Value = serde_json::from_str(
|
||||||
&globals
|
&globals
|
||||||
.reqwest_client()
|
.default_client()
|
||||||
.get(&format!(
|
.get(&format!(
|
||||||
"https://{}/.well-known/matrix/server",
|
"https://{}/.well-known/matrix/server",
|
||||||
destination
|
destination
|
||||||
|
Loading…
Reference in New Issue
Block a user