From a0e04c797b00154a76b50a6fe4015719b69ccaa3 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 29 Nov 2021 21:22:36 +0000 Subject: [PATCH] simplify default resolver lookup --- actix-tls/src/connect/connection.rs | 2 +- actix-tls/src/connect/info.rs | 12 ++++++------ actix-tls/src/connect/resolver.rs | 26 ++++++-------------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/actix-tls/src/connect/connection.rs b/actix-tls/src/connect/connection.rs index 4b454ef1..68972a2a 100644 --- a/actix-tls/src/connect/connection.rs +++ b/actix-tls/src/connect/connection.rs @@ -25,7 +25,7 @@ impl Connection { (self.io, self.req) } - /// Replaces underlying IO, returning old UI and new `Connection`. + /// Replaces underlying IO, returning old IO and new `Connection`. pub fn replace_io(self, io: IO2) -> (IO, Connection) { (self.io, Connection { io, req: self.req }) } diff --git a/actix-tls/src/connect/info.rs b/actix-tls/src/connect/info.rs index 85f9c961..ef283660 100644 --- a/actix-tls/src/connect/info.rs +++ b/actix-tls/src/connect/info.rs @@ -107,14 +107,14 @@ impl ConnectInfo { /// # Examples /// ``` /// # use std::net::SocketAddr; - /// # use actix_tls::connect::ConnectionInfo; + /// # use actix_tls::connect::ConnectInfo; /// let addr = SocketAddr::from(([127, 0, 0, 1], 4242)); /// - /// let conn = ConnectionInfo::new("localhost"); + /// let conn = ConnectInfo::new("localhost"); /// let mut addrs = conn.addrs(); /// assert!(addrs.next().is_none()); /// - /// let conn = ConnectionInfo::with_addr("localhost", addr); + /// let conn = ConnectInfo::with_addr("localhost", addr); /// let mut addrs = conn.addrs(); /// assert_eq!(addrs.next().unwrap(), addr); /// ``` @@ -138,14 +138,14 @@ impl ConnectInfo { /// # Examples /// ``` /// # use std::net::SocketAddr; - /// # use actix_tls::connect::ConnectionInfo; + /// # use actix_tls::connect::ConnectInfo; /// let addr = SocketAddr::from(([127, 0, 0, 1], 4242)); /// - /// let mut conn = ConnectionInfo::new("localhost"); + /// let mut conn = ConnectInfo::new("localhost"); /// let mut addrs = conn.take_addrs(); /// assert!(addrs.next().is_none()); /// - /// let mut conn = ConnectionInfo::with_addr("localhost", addr); + /// let mut conn = ConnectInfo::with_addr("localhost", addr); /// let mut addrs = conn.take_addrs(); /// assert_eq!(addrs.next().unwrap(), addr); /// ``` diff --git a/actix-tls/src/connect/resolver.rs b/actix-tls/src/connect/resolver.rs index d54d4217..7b6f14af 100644 --- a/actix-tls/src/connect/resolver.rs +++ b/actix-tls/src/connect/resolver.rs @@ -81,25 +81,11 @@ impl ResolverService { } /// Resolve DNS with default resolver. - fn look_up(req: &ConnectInfo) -> JoinHandle>> { - let host = req.hostname(); - // TODO: Connect should always return host(name?) with port if possible; basically try to - // reduce ability to create conflicting lookup info by having port in host string being - // different from numeric port in connect - - let host = if req - .hostname() - .split_once(':') - .and_then(|(_, port)| port.parse::().ok()) - .map(|port| port == req.port()) - .unwrap_or(false) - { - // if hostname contains port and also matches numeric port then just use the hostname - host.to_string() - } else { - // concatenate domain-only hostname and port together - format!("{}:{}", host, req.port()) - }; + fn default_lookup( + req: &ConnectInfo, + ) -> JoinHandle>> { + // reconstruct host; concatenate hostname and port together + let host = format!("{}:{}", req.hostname(), req.port()); // run blocking DNS lookup in thread pool since DNS lookups can take upwards of seconds on // some platforms if conditions are poor and OS-level cache is not populated @@ -126,7 +112,7 @@ impl Service> for ResolverService { match &self.kind { ResolverKind::Default => { - let fut = Self::look_up(&req); + let fut = Self::default_lookup(&req); ResolverFut::LookUp(fut, Some(req)) }