@@ -19,6 +19,11 @@ use std::sync::Arc;
1919use std:: task:: { Context , Poll } ;
2020use std:: { io, net} ;
2121use tokio:: io:: { AsyncRead , AsyncWrite } ;
22+ use tokio:: net:: TcpStream ;
23+ #[ cfg( feature = "runtime" ) ]
24+ use tower:: util:: MapResponse ;
25+ #[ cfg( feature = "runtime" ) ]
26+ use tower:: ServiceExt ;
2227use tower_layer:: Layer ;
2328use tower_service:: Service ;
2429
@@ -37,24 +42,38 @@ impl HttpsConnector<HttpConnector> {
3742 /// HTTP/2 and HTTP/1.1.
3843 ///
3944 /// Requires the `runtime` Cargo feature.
40- pub fn new ( ) -> Result < HttpsConnector < HttpConnector > , ErrorStack > {
45+ // This is a bit sad, but avoids requiring `TokioIo` as a response type below.
46+ #[ allow( clippy:: type_complexity) ]
47+ pub fn new ( ) -> Result <
48+ HttpsConnector <
49+ MapResponse <
50+ HttpConnector ,
51+ impl FnOnce ( TokioIo < TcpStream > ) -> TokioIo < TokioIo < TcpStream > > + Clone ,
52+ > ,
53+ > ,
54+ ErrorStack ,
55+ > {
4156 let mut http = HttpConnector :: new ( ) ;
4257 http. enforce_http ( false ) ;
4358
44- HttpsLayer :: new ( ) . map ( |l| l. layer ( http) )
59+ HttpsLayer :: new ( ) . map ( |l| l. layer ( http. map_response ( TokioIo :: new ) ) )
4560 }
4661}
4762
4863impl < S , T > HttpsConnector < S >
4964where
50- S : Service < Uri , Response = TokioIo < T > > + Send ,
65+ S : Service < Uri , Response = T > + Send ,
5166 S :: Error : Into < Box < dyn Error + Send + Sync > > ,
5267 S :: Future : Unpin + Send + ' static ,
5368 T : AsyncRead + AsyncWrite + Connection + Unpin + fmt:: Debug + Sync + Send + ' static ,
5469{
5570 /// Creates a new `HttpsConnector`.
5671 ///
5772 /// The session cache configuration of `ssl` will be overwritten.
73+ ///
74+ /// If the provided service's response type does not fit the trait
75+ /// requirements because it is closer to the Hyper ecosystem than the Tokio
76+ /// one, wrapping your responses with [`TokioIo`] should work.
5877 pub fn with_connector (
5978 http : S ,
6079 ssl : SslConnectorBuilder ,
@@ -215,7 +234,7 @@ impl Inner {
215234
216235impl < T , S > Service < Uri > for HttpsConnector < S >
217236where
218- S : Service < Uri , Response = TokioIo < T > > + Send ,
237+ S : Service < Uri , Response = T > + Send ,
219238 S :: Error : Into < Box < dyn Error + Send + Sync > > ,
220239 S :: Future : Unpin + Send + ' static ,
221240 T : AsyncRead + AsyncWrite + Connection + Unpin + fmt:: Debug + Sync + Send + ' static ,
@@ -244,7 +263,7 @@ where
244263 let connect = self . http . call ( uri) ;
245264
246265 let f = async {
247- let conn = connect. await . map_err ( Into :: into) ?. into_inner ( ) ;
266+ let conn = connect. await . map_err ( Into :: into) ?;
248267
249268 let ( inner, uri) = match tls_setup {
250269 Some ( ( inner, uri) ) => ( inner, uri) ,
0 commit comments