Skip to content

Commit

Permalink
fix(client): parse IPv6 hosts correctly in HttpConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jan 23, 2019
1 parent 7b7dcc8 commit c328c62
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/client/connect/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ impl IpAddrs {
let addr = SocketAddrV4::new(addr, port);
return Some(IpAddrs { iter: vec![SocketAddr::V4(addr)].into_iter() })
}
let host = {
// trim_left/trim_right deprecated...
// TODO: use trim_start/trim_end in Rust 1.30
#[allow(deprecated)]
{
host
.trim_left_matches('[')
.trim_right_matches(']')
}
};
if let Ok(addr) = host.parse::<Ipv6Addr>() {
let addr = SocketAddrV6::new(addr, port, 0, 0);
return Some(IpAddrs { iter: vec![SocketAddr::V6(addr)].into_iter() })
Expand Down Expand Up @@ -360,4 +370,19 @@ mod tests {
assert_eq!(name.as_str(), DOMAIN);
assert_eq!(name.to_string(), DOMAIN);
}

#[test]
fn ip_addrs_try_parse_v6() {
let uri = ::http::Uri::from_static("http://[::1]:8080/");
let dst = super::super::Destination { uri };

let mut addrs = IpAddrs::try_parse(
dst.host(),
dst.port().expect("port")
).expect("try_parse");

let expected = "[::1]:8080".parse::<SocketAddr>().expect("expected");

assert_eq!(addrs.next(), Some(expected));
}
}

0 comments on commit c328c62

Please sign in to comment.