mirror of https://github.com/fafhrd91/actix-net
				
				
				
			simplify default resolver lookup
This commit is contained in:
		
							parent
							
								
									3891745a6e
								
							
						
					
					
						commit
						a0e04c797b
					
				|  | @ -25,7 +25,7 @@ impl<R, IO> Connection<R, IO> { | ||||||
|         (self.io, self.req) |         (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<IO2>(self, io: IO2) -> (IO, Connection<R, IO2>) { |     pub fn replace_io<IO2>(self, io: IO2) -> (IO, Connection<R, IO2>) { | ||||||
|         (self.io, Connection { io, req: self.req }) |         (self.io, Connection { io, req: self.req }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -107,14 +107,14 @@ impl<R: Host> ConnectInfo<R> { | ||||||
|     /// # Examples
 |     /// # Examples
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     /// # use std::net::SocketAddr;
 |     /// # use std::net::SocketAddr;
 | ||||||
|     /// # use actix_tls::connect::ConnectionInfo;
 |     /// # use actix_tls::connect::ConnectInfo;
 | ||||||
|     /// let addr = SocketAddr::from(([127, 0, 0, 1], 4242));
 |     /// let addr = SocketAddr::from(([127, 0, 0, 1], 4242));
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// let conn = ConnectionInfo::new("localhost");
 |     /// let conn = ConnectInfo::new("localhost");
 | ||||||
|     /// let mut addrs = conn.addrs();
 |     /// let mut addrs = conn.addrs();
 | ||||||
|     /// assert!(addrs.next().is_none());
 |     /// assert!(addrs.next().is_none());
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// let conn = ConnectionInfo::with_addr("localhost", addr);
 |     /// let conn = ConnectInfo::with_addr("localhost", addr);
 | ||||||
|     /// let mut addrs = conn.addrs();
 |     /// let mut addrs = conn.addrs();
 | ||||||
|     /// assert_eq!(addrs.next().unwrap(), addr);
 |     /// assert_eq!(addrs.next().unwrap(), addr);
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|  | @ -138,14 +138,14 @@ impl<R: Host> ConnectInfo<R> { | ||||||
|     /// # Examples
 |     /// # Examples
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     /// # use std::net::SocketAddr;
 |     /// # use std::net::SocketAddr;
 | ||||||
|     /// # use actix_tls::connect::ConnectionInfo;
 |     /// # use actix_tls::connect::ConnectInfo;
 | ||||||
|     /// let addr = SocketAddr::from(([127, 0, 0, 1], 4242));
 |     /// 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();
 |     /// let mut addrs = conn.take_addrs();
 | ||||||
|     /// assert!(addrs.next().is_none());
 |     /// 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();
 |     /// let mut addrs = conn.take_addrs();
 | ||||||
|     /// assert_eq!(addrs.next().unwrap(), addr);
 |     /// assert_eq!(addrs.next().unwrap(), addr);
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|  |  | ||||||
|  | @ -81,25 +81,11 @@ impl ResolverService { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Resolve DNS with default resolver.
 |     /// Resolve DNS with default resolver.
 | ||||||
|     fn look_up<R: Host>(req: &ConnectInfo<R>) -> JoinHandle<io::Result<IntoIter<SocketAddr>>> { |     fn default_lookup<R: Host>( | ||||||
|         let host = req.hostname(); |         req: &ConnectInfo<R>, | ||||||
|         // TODO: Connect should always return host(name?) with port if possible; basically try to
 |     ) -> JoinHandle<io::Result<IntoIter<SocketAddr>>> { | ||||||
|         // reduce ability to create conflicting lookup info by having port in host string being
 |         // reconstruct host; concatenate hostname and port together
 | ||||||
|         // different from numeric port in connect
 |         let host = format!("{}:{}", req.hostname(), req.port()); | ||||||
| 
 |  | ||||||
|         let host = if req |  | ||||||
|             .hostname() |  | ||||||
|             .split_once(':') |  | ||||||
|             .and_then(|(_, port)| port.parse::<u16>().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()) |  | ||||||
|         }; |  | ||||||
| 
 | 
 | ||||||
|         // run blocking DNS lookup in thread pool since DNS lookups can take upwards of seconds on
 |         // 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
 |         // some platforms if conditions are poor and OS-level cache is not populated
 | ||||||
|  | @ -126,7 +112,7 @@ impl<R: Host> Service<ConnectInfo<R>> for ResolverService { | ||||||
| 
 | 
 | ||||||
|             match &self.kind { |             match &self.kind { | ||||||
|                 ResolverKind::Default => { |                 ResolverKind::Default => { | ||||||
|                     let fut = Self::look_up(&req); |                     let fut = Self::default_lookup(&req); | ||||||
|                     ResolverFut::LookUp(fut, Some(req)) |                     ResolverFut::LookUp(fut, Some(req)) | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue