Rename reqwest clients, mention cheap client clones in comment

This commit is contained in:
Aode (lion) 2022-01-28 12:42:47 -06:00
parent 1059f35fdc
commit b39ddf7be9
4 changed files with 16 additions and 16 deletions

View file

@ -46,7 +46,7 @@ where
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
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
let status = response.status();

View file

@ -39,8 +39,8 @@ pub struct Globals {
keypair: Arc<ruma::signatures::Ed25519KeyPair>,
dns_resolver: TokioAsyncResolver,
jwt_decoding_key: Option<jsonwebtoken::DecodingKey<'static>>,
well_known_client: reqwest::Client,
basic_client: reqwest::Client,
federation_client: reqwest::Client,
default_client: reqwest::Client,
pub(super) server_signingkeys: Arc<dyn Tree>,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<Box<EventId>, RateLimitState>>>,
pub bad_signature_ratelimiter: Arc<RwLock<HashMap<Vec<String>, RateLimitState>>>,
@ -134,9 +134,9 @@ impl Globals {
.as_ref()
.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 well_known_client = reqwest_client_builder(&config)?
let federation_client = reqwest_client_builder(&config)?
.resolve_fn(move |domain| {
let read_guard = name_override.read().unwrap();
let (override_name, port) = read_guard.get(&domain)?;
@ -154,8 +154,8 @@ impl Globals {
})?,
actual_destination_cache: Arc::new(RwLock::new(WellKnownMap::new())),
tls_name_override,
well_known_client,
basic_client,
federation_client,
default_client,
server_signingkeys,
jwt_decoding_key,
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
pub fn reqwest_client(&self) -> reqwest::Client {
// can't return &Client or else we'll hold a lock around the DB across an await
self.basic_client.clone()
pub fn default_client(&self) -> reqwest::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self.default_client.clone()
}
/// Returns a client used for resolving .well-knowns
pub fn well_known_client(&self) -> reqwest::Client {
// can't return &Client or else we'll hold a lock around the DB across an await
self.well_known_client.clone()
pub fn federation_client(&self) -> reqwest::Client {
// Client is cheap to clone (Arc wrapper) and avoids lifetime issues
self.federation_client.clone()
}
#[tracing::instrument(skip(self))]

View file

@ -115,7 +115,7 @@ where
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
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 {
Ok(mut response) => {

View file

@ -237,7 +237,7 @@ where
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 {
Ok(mut response) => {
@ -477,7 +477,7 @@ async fn request_well_known(
) -> Option<String> {
let body: serde_json::Value = serde_json::from_str(
&globals
.reqwest_client()
.default_client()
.get(&format!(
"https://{}/.well-known/matrix/server",
destination