From e6daca799555c6bfd1886bfcb7631ed0eab5b084 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 10 Dec 2018 18:08:07 -0800 Subject: [PATCH] try to parse host first --- actix-connector/src/resolver.rs | 18 +++++++++++------- actix-server/src/accept.rs | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/actix-connector/src/resolver.rs b/actix-connector/src/resolver.rs index bb580ca1e..ae085e5b1 100644 --- a/actix-connector/src/resolver.rs +++ b/actix-connector/src/resolver.rs @@ -2,10 +2,8 @@ use std::collections::VecDeque; use std::marker::PhantomData; use std::net::IpAddr; -use futures::{Async, Future, Poll}; - -use actix_rt::spawn; use actix_service::Service; +use futures::{Async, Future, Poll}; use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; pub use trust_dns_resolver::error::ResolveError; use trust_dns_resolver::lookup_ip::LookupIpFuture; @@ -44,7 +42,7 @@ impl Resolver { /// Create new resolver instance with custom configuration and options. pub fn new(cfg: ResolverConfig, opts: ResolverOpts) -> Self { let (resolver, bg) = AsyncResolver::new(cfg, opts); - spawn(bg); + actix_rt::Arbiter::spawn(bg); Resolver { resolver, req: PhantomData, @@ -79,7 +77,13 @@ impl Service for Resolver { } fn call(&mut self, req: T) -> Self::Future { - ResolverFuture::new(req, &self.resolver) + if let Ok(ip) = req.host().parse() { + let mut addrs = VecDeque::new(); + addrs.push_back(ip); + ResolverFuture::new(req, &self.resolver, Some(addrs)) + } else { + ResolverFuture::new(req, &self.resolver, None) + } } } @@ -92,13 +96,13 @@ pub struct ResolverFuture { } impl ResolverFuture { - pub fn new(addr: T, resolver: &AsyncResolver) -> Self { + pub fn new(addr: T, resolver: &AsyncResolver, addrs: Option>) -> Self { // we need to do dns resolution let lookup = Some(resolver.lookup_ip(addr.host())); ResolverFuture { lookup, + addrs, req: Some(addr), - addrs: None, } } } diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index ca7265016..e02fb05fc 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -143,7 +143,7 @@ impl Accept { // start accept thread let _ = thread::Builder::new() - .name("actix-web accept loop".to_owned()) + .name("actix-server accept loop".to_owned()) .spawn(move || { System::set_current(sys); let mut accept = Accept::new(rx, socks, workers, srv);