From 2c3d5cf64662035a8cbdee5ef65414faa1bc1641 Mon Sep 17 00:00:00 2001 From: Jun Kurihara Date: Tue, 21 Nov 2023 00:52:55 +0900 Subject: [PATCH] fix: fix bug for ip address host name --- proxy-lib/src/trait_resolve_ips.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/proxy-lib/src/trait_resolve_ips.rs b/proxy-lib/src/trait_resolve_ips.rs index 92f7b09..7a0b1eb 100644 --- a/proxy-lib/src/trait_resolve_ips.rs +++ b/proxy-lib/src/trait_resolve_ips.rs @@ -19,7 +19,19 @@ pub struct ResolveIpResponse { /// Resolve ip addresses for given endpoints pub async fn resolve_ips(endpoints: &[Url], resolver_ips: impl ResolveIps) -> Result> { - let resolve_ips_fut = endpoints.iter().map(|endpoint| resolver_ips.resolve_ips(endpoint)); + let resolve_ips_fut = endpoints.iter().map(|endpoint| async { + let host_is_ipaddr = endpoint + .host_str() + .map_or(false, |host| host.parse::().is_ok()); + if host_is_ipaddr { + Ok(ResolveIpResponse { + hostname: endpoint.host_str().unwrap().to_string(), + addresses: vec![endpoint.socket_addrs(|| None).unwrap()[0]], + }) + } else { + resolver_ips.resolve_ips(endpoint).await + } + }); let resolve_ips = futures::future::join_all(resolve_ips_fut).await; if resolve_ips.iter().any(|resolve_ip| resolve_ip.is_err()) { return Err(DapError::FailedToResolveIpsForHttpClient);