mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 01:11:07 +01:00
try to parse host first
This commit is contained in:
parent
d35c87d228
commit
e6daca7995
@ -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<T: RequestHost> Resolver<T> {
|
||||
/// 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<T: RequestHost> Service<T> for Resolver<T> {
|
||||
}
|
||||
|
||||
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> {
|
||||
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
|
||||
let lookup = Some(resolver.lookup_ip(addr.host()));
|
||||
ResolverFuture {
|
||||
lookup,
|
||||
addrs,
|
||||
req: Some(addr),
|
||||
addrs: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user