diff --git a/src/ssl/openssl.rs b/src/ssl/openssl.rs index e1de2dbc7..319740dd6 100644 --- a/src/ssl/openssl.rs +++ b/src/ssl/openssl.rs @@ -1,7 +1,7 @@ use std::io; use std::marker::PhantomData; -use futures::{future, future::FutureResult, Async, Poll}; +use futures::{future, future::FutureResult, Async, Poll, Future}; use openssl::ssl::{AlpnError, Error, SslAcceptor, SslAcceptorBuilder, SslConnector}; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_openssl::{AcceptAsync, ConnectAsync, SslAcceptorExt, SslConnectorExt, SslStream}; @@ -116,7 +116,7 @@ impl Clone for OpensslConnector { impl NewService for OpensslConnector { type Request = (String, T); - type Response = SslStream; + type Response = (String, SslStream); type Error = Error; type Service = OpensslConnectorService; type InitError = io::Error; @@ -137,15 +137,38 @@ pub struct OpensslConnectorService { impl Service for OpensslConnectorService { type Request = (String, T); - type Response = SslStream; + type Response = (String, SslStream); type Error = Error; - type Future = ConnectAsync; + type Future = ConnectAsyncExt; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) } fn call(&mut self, (host, stream): Self::Request) -> Self::Future { - SslConnectorExt::connect_async(&self.connector, &host, stream) + ConnectAsyncExt { + fut: SslConnectorExt::connect_async(&self.connector, &host, stream), + host: Some(host) + } } } + +pub struct ConnectAsyncExt { + fut: ConnectAsync, + host: Option, +} + +impl Future for ConnectAsyncExt +where + T: AsyncRead + AsyncWrite, +{ + type Item = (String, SslStream); + type Error = Error; + + fn poll(&mut self) -> Poll { + match self.fut.poll()? { + Async::Ready(stream) => Ok(Async::Ready((self.host.take().unwrap(), stream))), + Async::NotReady => Ok(Async::NotReady) + } + } +} \ No newline at end of file