Skip to content

Commit dfe01a1

Browse files
authored
Merge pull request #837 from hatoo/fix-mac-localhost
Prefer ipv6 for localhost on macos
2 parents 8dc6349 + 3a89525 commit dfe01a1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,17 @@ pub async fn run(mut opts: Opts) -> anyhow::Result<()> {
542542
let proxy_headers = opts.proxy_headers.into_iter().collect::<HeaderMap<_>>();
543543

544544
let ip_strategy = match (opts.ipv4, opts.ipv6) {
545-
(false, false) => Default::default(),
545+
(false, false) => {
546+
if cfg!(target_os = "macos") && (url.host_str() == Some("localhost")) {
547+
// #784
548+
// On macOS, localhost resolves to ::1 first, So web servers that bind to localhost tend to listen ipv6 only.
549+
// So prefer ipv6 on macos for localhost.
550+
551+
hickory_resolver::config::LookupIpStrategy::Ipv6thenIpv4
552+
} else {
553+
Default::default()
554+
}
555+
}
546556
(true, false) => hickory_resolver::config::LookupIpStrategy::Ipv4Only,
547557
(false, true) => hickory_resolver::config::LookupIpStrategy::Ipv6Only,
548558
(true, true) => hickory_resolver::config::LookupIpStrategy::Ipv4AndIpv6,

0 commit comments

Comments
 (0)