@@ -7,6 +7,7 @@ mod pool;
77pub mod conn;
88pub mod connect;
99pub ( super ) mod dispatch;
10+ pub mod future;
1011pub mod options;
1112pub mod proxy;
1213
@@ -21,15 +22,15 @@ use std::{
2122 time:: Duration ,
2223} ;
2324
24- use futures_util:: future:: { self , Either , FutureExt , TryFutureExt } ;
25+ use future:: ResponseFuture ;
26+ use futures_util:: future:: { Either , FutureExt , TryFutureExt } ;
2527use http:: {
2628 HeaderValue , Method , Request , Response , Uri , Version ,
2729 header:: HOST ,
2830 uri:: { Authority , PathAndQuery , Scheme } ,
2931} ;
3032use http_body:: Body ;
3133use pool:: Ver ;
32- use sync_wrapper:: SyncWrapper ;
3334use tower:: util:: Oneshot ;
3435
3536use crate :: {
@@ -225,15 +226,6 @@ enum TrySendError<B> {
225226 Nope ( Error ) ,
226227}
227228
228- type ResponseWrapper =
229- SyncWrapper < Pin < Box < dyn Future < Output = Result < Response < Incoming > , Error > > + Send > > > ;
230-
231- /// A `Future` that will resolve to an HTTP Response.
232- #[ must_use = "futures do nothing unless polled" ]
233- pub struct ResponseFuture {
234- inner : ResponseWrapper ,
235- }
236-
237229// ===== impl HttpClient =====
238230
239231impl HttpClient < ( ) , ( ) > {
@@ -263,17 +255,22 @@ where
263255 match req. version ( ) {
264256 Version :: HTTP_10 if is_http_connect => {
265257 warn ! ( "CONNECT is not allowed for HTTP/1.0" ) ;
266- return ResponseFuture :: new ( future:: err ( e ! ( UserUnsupportedRequestMethod ) ) ) ;
258+ return ResponseFuture :: new ( futures_util:: future:: err ( e ! (
259+ UserUnsupportedRequestMethod
260+ ) ) ) ;
267261 }
268262 Version :: HTTP_10 | Version :: HTTP_11 | Version :: HTTP_2 => { }
269263 // completely unsupported HTTP version (like HTTP/0.9)!
270- unsupported => return ResponseFuture :: error_version ( unsupported) ,
264+ _unsupported => {
265+ warn ! ( "Request has unsupported version \" {:?}\" " , _unsupported) ;
266+ return ResponseFuture :: new ( futures_util:: future:: err ( e ! ( UserUnsupportedVersion ) ) ) ;
267+ }
271268 } ;
272269
273270 // Extract and normalize URI
274271 let uri = match normalize_uri ( & mut req, is_http_connect) {
275272 Ok ( uri) => uri,
276- Err ( err) => return ResponseFuture :: new ( future:: err ( err) ) ,
273+ Err ( err) => return ResponseFuture :: new ( futures_util :: future:: err ( err) ) ,
277274 } ;
278275
279276 // Extract config extensions
@@ -490,7 +487,7 @@ where
490487
491488 // The order of the `select` is depended on below...
492489
493- match future:: select ( checkout, connect) . await {
490+ match futures_util :: future:: select ( checkout, connect) . await {
494491 // Checkout won, connect future may have been started or not.
495492 //
496493 // If it has, let it finish and insert back into the pool,
@@ -577,7 +574,7 @@ where
577574 None => {
578575 let canceled = e ! ( Canceled ) ;
579576 // HTTP/2 connection in progress.
580- return Either :: Right ( future:: err ( canceled) ) ;
577+ return Either :: Right ( futures_util :: future:: err ( canceled) ) ;
581578 }
582579 } ;
583580 Either :: Left (
@@ -598,7 +595,7 @@ where
598595 // Another connection has already upgraded,
599596 // the pool checkout should finish up for us.
600597 let canceled = e ! ( Canceled , "ALPN upgraded to HTTP/2" ) ;
601- return Either :: Right ( future:: err ( canceled) ) ;
598+ return Either :: Right ( futures_util :: future:: err ( canceled) ) ;
602599 }
603600 }
604601 } else {
@@ -796,38 +793,6 @@ impl<C, B> fmt::Debug for HttpClient<C, B> {
796793 }
797794}
798795
799- // ===== impl ResponseFuture =====
800-
801- impl ResponseFuture {
802- fn new < F > ( value : F ) -> Self
803- where
804- F : Future < Output = Result < Response < Incoming > , Error > > + Send + ' static ,
805- {
806- Self {
807- inner : SyncWrapper :: new ( Box :: pin ( value) ) ,
808- }
809- }
810-
811- fn error_version ( _ver : Version ) -> Self {
812- warn ! ( "Request has unsupported version \" {:?}\" " , _ver) ;
813- ResponseFuture :: new ( Box :: pin ( future:: err ( e ! ( UserUnsupportedVersion ) ) ) )
814- }
815- }
816-
817- impl fmt:: Debug for ResponseFuture {
818- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
819- f. pad ( "Future<Response>" )
820- }
821- }
822-
823- impl Future for ResponseFuture {
824- type Output = Result < Response < Incoming > , Error > ;
825-
826- fn poll ( mut self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
827- self . inner . get_mut ( ) . as_mut ( ) . poll ( cx)
828- }
829- }
830-
831796/// A pooled HTTP connection that can send requests
832797struct PoolClient < B > {
833798 conn_info : Connected ,
0 commit comments