Skip to content

Commit d769f8a

Browse files
committed
Don't DNS resolve localhost
1 parent 99b2254 commit d769f8a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

crates/client/src/dns.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub(crate) fn validate_and_get_dns_lb(
3939
.ok_or_else(|| ClientConnectError::InvalidConfig("target URL has no host".to_owned()))?;
4040

4141
match host {
42+
url::Host::Domain("localhost") => Ok(None),
4243
url::Host::Domain(_) => Ok(Some(dns_opts)),
4344
url::Host::Ipv4(_) | url::Host::Ipv6(_) => Ok(None),
4445
}
@@ -285,6 +286,12 @@ mod tests {
285286
assert!(validate_and_get_dns_lb(&opts).is_err());
286287
}
287288

289+
#[test]
290+
fn localhost_returns_none() {
291+
let opts = ConnectionOptions::new(Url::parse("http://localhost:7233").unwrap()).build();
292+
assert!(validate_and_get_dns_lb(&opts).unwrap().is_none());
293+
}
294+
288295
#[test]
289296
fn endpoint_uri_v4() {
290297
let addr: SocketAddr = "1.2.3.4:7233".parse().unwrap();

0 commit comments

Comments
 (0)