1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 19:54:36 +01:00

try to parse host first

This commit is contained in:
Nikolay Kim 2018-12-10 18:08:07 -08:00
parent d35c87d228
commit e6daca7995
2 changed files with 12 additions and 8 deletions

View File

@ -2,10 +2,8 @@ use std::collections::VecDeque;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::net::IpAddr; use std::net::IpAddr;
use futures::{Async, Future, Poll};
use actix_rt::spawn;
use actix_service::Service; use actix_service::Service;
use futures::{Async, Future, Poll};
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
pub use trust_dns_resolver::error::ResolveError; pub use trust_dns_resolver::error::ResolveError;
use trust_dns_resolver::lookup_ip::LookupIpFuture; use trust_dns_resolver::lookup_ip::LookupIpFuture;
@ -44,7 +42,7 @@ impl<T: RequestHost> Resolver<T> {
/// Create new resolver instance with custom configuration and options. /// Create new resolver instance with custom configuration and options.
pub fn new(cfg: ResolverConfig, opts: ResolverOpts) -> Self { pub fn new(cfg: ResolverConfig, opts: ResolverOpts) -> Self {
let (resolver, bg) = AsyncResolver::new(cfg, opts); let (resolver, bg) = AsyncResolver::new(cfg, opts);
spawn(bg); actix_rt::Arbiter::spawn(bg);
Resolver { Resolver {
resolver, resolver,
req: PhantomData, req: PhantomData,
@ -79,7 +77,13 @@ impl<T: RequestHost> Service<T> for Resolver<T> {
} }
fn call(&mut self, req: T) -> Self::Future { 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<T> {
} }
impl<T: RequestHost> ResolverFuture<T> { impl<T: RequestHost> ResolverFuture<T> {
pub fn new(addr: T, resolver: &AsyncResolver) -> Self { pub fn new(addr: T, resolver: &AsyncResolver, addrs: Option<VecDeque<IpAddr>>) -> Self {
// we need to do dns resolution // we need to do dns resolution
let lookup = Some(resolver.lookup_ip(addr.host())); let lookup = Some(resolver.lookup_ip(addr.host()));
ResolverFuture { ResolverFuture {
lookup, lookup,
addrs,
req: Some(addr), req: Some(addr),
addrs: None,
} }
} }
} }

View File

@ -143,7 +143,7 @@ impl Accept {
// start accept thread // start accept thread
let _ = thread::Builder::new() let _ = thread::Builder::new()
.name("actix-web accept loop".to_owned()) .name("actix-server accept loop".to_owned())
.spawn(move || { .spawn(move || {
System::set_current(sys); System::set_current(sys);
let mut accept = Accept::new(rx, socks, workers, srv); let mut accept = Accept::new(rx, socks, workers, srv);