|
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 |
10 | 9 | #[cfg(not(wasm_browser))] |
11 | 10 | pub(crate) fn reqwest_client_builder( |
12 | 11 | tls_client_config: rustls::ClientConfig, |
13 | 12 | dns_resolver: crate::dns::DnsResolver, |
14 | 13 | ) -> reqwest::ClientBuilder { |
15 | | - use std::sync::Arc; |
16 | | - |
17 | 14 | use self::reqwest_dns_resolver::ReqwestDnsResolver; |
18 | 15 |
|
19 | 16 | 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() |
22 | 24 | } |
23 | 25 |
|
24 | 26 | #[cfg(not(wasm_browser))] |
25 | 27 | 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; |
33 | 29 |
|
34 | | - const DNS_TIMEOUT: Duration = Duration::from_secs(3); |
| 30 | + use iroh_dns::dns::{DNS_TIMEOUT, DnsResolver}; |
35 | 31 |
|
| 32 | + /// Implementation of [`reqwest::dns::Resolve`] for [`DnsResolver`]. |
| 33 | + /// |
| 34 | + /// Wrapped in a newtype to not expose this in the public iroh API. |
36 | 35 | pub(super) struct ReqwestDnsResolver(pub(super) DnsResolver); |
37 | 36 |
|
38 | 37 | impl reqwest::dns::Resolve for ReqwestDnsResolver { |
|
0 commit comments