Skip to content

Commit

Permalink
fix: fix bug for ip address host name
Browse files Browse the repository at this point in the history
  • Loading branch information
junkurihara committed Nov 20, 2023
1 parent bb0cf69 commit 2c3d5cf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion proxy-lib/src/trait_resolve_ips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<ResolveIpResponse>> {
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::<std::net::IpAddr>().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);
Expand Down

0 comments on commit 2c3d5cf

Please sign in to comment.