feat(client): skip dns resolution when host is a valid ip addr (#1372)

This commit is contained in:
Sam Rijs
2017-11-14 10:00:34 +11:00
committed by Sean McArthur
parent e330d30964
commit b1785c662b
2 changed files with 31 additions and 4 deletions

View File

@@ -186,9 +186,18 @@ impl Future for HttpConnecting {
let state;
match self.state {
State::Lazy(ref executor, ref mut host, port) => {
let host = mem::replace(host, String::new());
let work = dns::Work::new(host, port);
state = State::Resolving(oneshot::spawn(work, executor));
// If the host is already an IP addr (v4 or v6),
// skip resolving the dns and start connecting right away.
if let Some(addrs) = dns::IpAddrs::try_parse(host, port) {
state = State::Connecting(ConnectingTcp {
addrs: addrs,
current: None
})
} else {
let host = mem::replace(host, String::new());
let work = dns::Work::new(host, port);
state = State::Resolving(oneshot::spawn(work, executor));
}
},
State::Resolving(ref mut future) => {
match try!(future.poll()) {