mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-15 15:16:37 +00:00
Enable happy eyeballs when using hickory-dns
Ported from seanmonstar/reqwest#2378 Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
parent
43012ceb2c
commit
651a82a4da
1 changed files with 36 additions and 30 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{net::SocketAddr, sync::Arc};
|
||||
|
||||
use hickory_resolver::TokioAsyncResolver;
|
||||
use hickory_resolver::{system_conf, TokioAsyncResolver};
|
||||
use once_cell::sync::OnceCell;
|
||||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||
use tracing::{debug, instrument, warn};
|
||||
|
@ -26,15 +26,14 @@ impl Resolve for TrustDnsResolver {
|
|||
}
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
fn get_configs() -> Result<(ResolverConfig, ResolverOpts), BoxError> {
|
||||
debug!("Using system DNS resolver configuration");
|
||||
Ok(TokioAsyncResolver::tokio_from_system_conf()?)
|
||||
system_conf::read_system_conf().map_err(Into::into)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
fn get_configs() -> Result<(ResolverConfig, ResolverOpts), BoxError> {
|
||||
debug!("Using custom DNS resolver configuration");
|
||||
let mut config = ResolverConfig::new();
|
||||
let opts = ResolverOpts::default();
|
||||
|
@ -55,9 +54,16 @@ fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
|||
}
|
||||
});
|
||||
|
||||
debug!("Resolver configuration complete");
|
||||
Ok(TokioAsyncResolver::tokio(config, opts))
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
fn new_resolver() -> Result<TokioAsyncResolver, BoxError> {
|
||||
let (config, mut opts) = get_configs()?;
|
||||
|
||||
debug!("Resolver configuration complete");
|
||||
opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;
|
||||
Ok(TokioAsyncResolver::tokio(config, opts))
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue