mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 19:12:56 +01:00
use RequestHost trait for OpensslConnector service
This commit is contained in:
parent
9b9599500a
commit
8f20f69559
@ -6,8 +6,8 @@ use tokio_io::{AsyncRead, AsyncWrite};
|
|||||||
use tokio_openssl::{AcceptAsync, ConnectAsync, SslAcceptorExt, SslConnectorExt, SslStream};
|
use tokio_openssl::{AcceptAsync, ConnectAsync, SslAcceptorExt, SslConnectorExt, SslStream};
|
||||||
|
|
||||||
use super::MAX_CONN_COUNTER;
|
use super::MAX_CONN_COUNTER;
|
||||||
use connector::Connect;
|
|
||||||
use counter::{Counter, CounterGuard};
|
use counter::{Counter, CounterGuard};
|
||||||
|
use resolver::RequestHost;
|
||||||
use service::{NewService, Service};
|
use service::{NewService, Service};
|
||||||
|
|
||||||
/// Support `SSL` connections via openssl package
|
/// Support `SSL` connections via openssl package
|
||||||
@ -102,12 +102,12 @@ impl<T: AsyncRead + AsyncWrite> Future for OpensslAcceptorServiceFut<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Openssl connector factory
|
/// Openssl connector factory
|
||||||
pub struct OpensslConnector<T, E> {
|
pub struct OpensslConnector<R, T, E> {
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
_t: PhantomData<(T, E)>,
|
_t: PhantomData<(R, T, E)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> OpensslConnector<T, E> {
|
impl<R, T, E> OpensslConnector<R, T, E> {
|
||||||
pub fn new(connector: SslConnector) -> Self {
|
pub fn new(connector: SslConnector) -> Self {
|
||||||
OpensslConnector {
|
OpensslConnector {
|
||||||
connector,
|
connector,
|
||||||
@ -116,11 +116,10 @@ impl<T, E> OpensslConnector<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite> OpensslConnector<T, ()> {
|
impl<R: RequestHost, T: AsyncRead + AsyncWrite> OpensslConnector<R, T, ()> {
|
||||||
pub fn service(
|
pub fn service(
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
) -> impl Service<Request = (Connect, T), Response = (Connect, SslStream<T>), Error = Error>
|
) -> impl Service<Request = (R, T), Response = (R, SslStream<T>), Error = Error> {
|
||||||
{
|
|
||||||
OpensslConnectorService {
|
OpensslConnectorService {
|
||||||
connector: connector,
|
connector: connector,
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
@ -128,7 +127,7 @@ impl<T: AsyncRead + AsyncWrite> OpensslConnector<T, ()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> Clone for OpensslConnector<T, E> {
|
impl<R, T, E> Clone for OpensslConnector<R, T, E> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connector: self.connector.clone(),
|
connector: self.connector.clone(),
|
||||||
@ -137,11 +136,11 @@ impl<T, E> Clone for OpensslConnector<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite, E> NewService for OpensslConnector<T, E> {
|
impl<R: RequestHost, T: AsyncRead + AsyncWrite, E> NewService for OpensslConnector<R, T, E> {
|
||||||
type Request = (Connect, T);
|
type Request = (R, T);
|
||||||
type Response = (Connect, SslStream<T>);
|
type Response = (R, SslStream<T>);
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Service = OpensslConnectorService<T>;
|
type Service = OpensslConnectorService<R, T>;
|
||||||
type InitError = E;
|
type InitError = E;
|
||||||
type Future = FutureResult<Self::Service, Self::InitError>;
|
type Future = FutureResult<Self::Service, Self::InitError>;
|
||||||
|
|
||||||
@ -153,16 +152,16 @@ impl<T: AsyncRead + AsyncWrite, E> NewService for OpensslConnector<T, E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OpensslConnectorService<T> {
|
pub struct OpensslConnectorService<R, T> {
|
||||||
connector: SslConnector,
|
connector: SslConnector,
|
||||||
_t: PhantomData<T>,
|
_t: PhantomData<(R, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite> Service for OpensslConnectorService<T> {
|
impl<R: RequestHost, T: AsyncRead + AsyncWrite> Service for OpensslConnectorService<R, T> {
|
||||||
type Request = (Connect, T);
|
type Request = (R, T);
|
||||||
type Response = (Connect, SslStream<T>);
|
type Response = (R, SslStream<T>);
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = ConnectAsyncExt<T>;
|
type Future = ConnectAsyncExt<R, T>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
@ -170,22 +169,23 @@ impl<T: AsyncRead + AsyncWrite> Service for OpensslConnectorService<T> {
|
|||||||
|
|
||||||
fn call(&mut self, (req, stream): Self::Request) -> Self::Future {
|
fn call(&mut self, (req, stream): Self::Request) -> Self::Future {
|
||||||
ConnectAsyncExt {
|
ConnectAsyncExt {
|
||||||
fut: SslConnectorExt::connect_async(&self.connector, &req.host, stream),
|
fut: SslConnectorExt::connect_async(&self.connector, req.host(), stream),
|
||||||
req: Some(req),
|
req: Some(req),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ConnectAsyncExt<T> {
|
pub struct ConnectAsyncExt<R, T> {
|
||||||
|
req: Option<R>,
|
||||||
fut: ConnectAsync<T>,
|
fut: ConnectAsync<T>,
|
||||||
req: Option<Connect>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Future for ConnectAsyncExt<T>
|
impl<R, T> Future for ConnectAsyncExt<R, T>
|
||||||
where
|
where
|
||||||
|
R: RequestHost,
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type Item = (Connect, SslStream<T>);
|
type Item = (R, SslStream<T>);
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user