Skip to content

Commit 00b59af

Browse files
committed
refactor(iroh): cleanup reqwest client builder util
1 parent 07f1d1a commit 00b59af

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

iroh/src/util.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
//! Utilities used in [`iroh`][`crate`]
2-
3-
#[cfg(wasm_browser)]
4-
pub(crate) fn reqwest_client_builder() -> reqwest::ClientBuilder {
5-
reqwest::Client::builder()
6-
}
7-
8-
/// Creates a reqwest client builder that always uses the rustls backend, unless we
9-
/// are in a browser context, where that is not supported.
1+
//! Utilities used in [`iroh`](crate).
2+
3+
/// Creates a [`reqwest::ClientBuilder`] from a [`rustls::ClientConfig`] and our [`DnsResolver`].
4+
///
5+
/// In a browser context these options are not supported, so this function takes no arguments
6+
/// if `wasm_browser` is enabled.
7+
///
8+
/// [`DnsResolver`]: crate::dns::DnsResolver
109
#[cfg(not(wasm_browser))]
1110
pub(crate) fn reqwest_client_builder(
1211
tls_client_config: rustls::ClientConfig,
1312
dns_resolver: crate::dns::DnsResolver,
1413
) -> reqwest::ClientBuilder {
15-
use std::sync::Arc;
16-
1714
use self::reqwest_dns_resolver::ReqwestDnsResolver;
1815

1916
reqwest::Client::builder()
20-
.use_preconfigured_tls(tls_client_config)
21-
.dns_resolver(Arc::new(ReqwestDnsResolver(dns_resolver)))
17+
.tls_backend_preconfigured(tls_client_config)
18+
.dns_resolver(ReqwestDnsResolver(dns_resolver))
19+
}
20+
21+
#[cfg(wasm_browser)]
22+
pub(crate) fn reqwest_client_builder() -> reqwest::ClientBuilder {
23+
reqwest::Client::builder()
2224
}
2325

2426
#[cfg(not(wasm_browser))]
2527
mod reqwest_dns_resolver {
26-
//! Implementation of [`reqwest::dns::Resolve`] for [`DnsResolver`].
27-
//!
28-
//! Wrapped in a newtype to not expose this in the public iroh API.
29-
30-
use std::{net::SocketAddr, time::Duration};
31-
32-
use iroh_dns::dns::DnsResolver;
28+
use std::net::SocketAddr;
3329

34-
const DNS_TIMEOUT: Duration = Duration::from_secs(3);
30+
use iroh_dns::dns::{DNS_TIMEOUT, DnsResolver};
3531

32+
/// Implementation of [`reqwest::dns::Resolve`] for [`DnsResolver`].
33+
///
34+
/// Wrapped in a newtype to not expose this in the public iroh API.
3635
pub(super) struct ReqwestDnsResolver(pub(super) DnsResolver);
3736

3837
impl reqwest::dns::Resolve for ReqwestDnsResolver {

0 commit comments

Comments
 (0)