48
48
49
49
use std:: error:: Error as StdError ;
50
50
use std:: fmt;
51
- #[ cfg( feature = "http2" ) ]
51
+ #[ cfg( not ( all ( feature = "http1" , feature = " http2") ) ) ]
52
52
use std:: marker:: PhantomData ;
53
53
use std:: sync:: Arc ;
54
54
#[ cfg( all( feature = "runtime" , feature = "http2" ) ) ]
@@ -57,12 +57,14 @@ use std::time::Duration;
57
57
use bytes:: Bytes ;
58
58
use futures_util:: future:: { self , Either , FutureExt as _} ;
59
59
use httparse:: ParserConfig ;
60
- use pin_project :: pin_project;
60
+ use pin_project_lite :: pin_project;
61
61
use tokio:: io:: { AsyncRead , AsyncWrite } ;
62
62
use tower_service:: Service ;
63
63
64
64
use super :: dispatch;
65
65
use crate :: body:: HttpBody ;
66
+ #[ cfg( not( all( feature = "http1" , feature = "http2" ) ) ) ]
67
+ use crate :: common:: Never ;
66
68
use crate :: common:: {
67
69
exec:: { BoxSendFuture , Exec } ,
68
70
task, Future , Pin , Poll ,
@@ -74,17 +76,33 @@ use crate::upgrade::Upgraded;
74
76
use crate :: { Body , Request , Response } ;
75
77
76
78
#[ cfg( feature = "http1" ) ]
77
- type Http1Dispatcher < T , B , R > = proto:: dispatch:: Dispatcher < proto:: dispatch:: Client < B > , B , T , R > ;
79
+ type Http1Dispatcher < T , B > =
80
+ proto:: dispatch:: Dispatcher < proto:: dispatch:: Client < B > , B , T , proto:: h1:: ClientTransaction > ;
78
81
79
- #[ pin_project( project = ProtoClientProj ) ]
80
- enum ProtoClient < T , B >
81
- where
82
- B : HttpBody ,
83
- {
84
- #[ cfg( feature = "http1" ) ]
85
- H1 ( #[ pin] Http1Dispatcher < T , B , proto:: h1:: ClientTransaction > ) ,
86
- #[ cfg( feature = "http2" ) ]
87
- H2 ( #[ pin] proto:: h2:: ClientTask < B > , PhantomData < fn ( T ) > ) ,
82
+ #[ cfg( not( feature = "http1" ) ) ]
83
+ type Http1Dispatcher < T , B > = ( Never , PhantomData < ( T , Pin < Box < B > > ) > ) ;
84
+
85
+ #[ cfg( feature = "http2" ) ]
86
+ type Http2ClientTask < B > = proto:: h2:: ClientTask < B > ;
87
+
88
+ #[ cfg( not( feature = "http2" ) ) ]
89
+ type Http2ClientTask < B > = ( Never , PhantomData < Pin < Box < B > > > ) ;
90
+
91
+ pin_project ! {
92
+ #[ project = ProtoClientProj ]
93
+ enum ProtoClient <T , B >
94
+ where
95
+ B : HttpBody ,
96
+ {
97
+ H1 {
98
+ #[ pin]
99
+ h1: Http1Dispatcher <T , B >,
100
+ } ,
101
+ H2 {
102
+ #[ pin]
103
+ h2: Http2ClientTask <B >,
104
+ } ,
105
+ }
88
106
}
89
107
90
108
/// Returns a handshake future over some IO.
@@ -405,18 +423,20 @@ where
405
423
pub fn into_parts ( self ) -> Parts < T > {
406
424
match self . inner . expect ( "already upgraded" ) {
407
425
#[ cfg( feature = "http1" ) ]
408
- ProtoClient :: H1 ( h1 ) => {
426
+ ProtoClient :: H1 { h1 } => {
409
427
let ( io, read_buf, _) = h1. into_inner ( ) ;
410
428
Parts {
411
429
io,
412
430
read_buf,
413
431
_inner : ( ) ,
414
432
}
415
433
}
416
- #[ cfg( feature = "http2" ) ]
417
- ProtoClient :: H2 ( ..) => {
434
+ ProtoClient :: H2 { .. } => {
418
435
panic ! ( "http2 cannot into_inner" ) ;
419
436
}
437
+
438
+ #[ cfg( not( feature = "http1" ) ) ]
439
+ ProtoClient :: H1 { h1 } => match h1. 0 { } ,
420
440
}
421
441
}
422
442
@@ -434,9 +454,14 @@ where
434
454
pub fn poll_without_shutdown ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < crate :: Result < ( ) > > {
435
455
match * self . inner . as_mut ( ) . expect ( "already upgraded" ) {
436
456
#[ cfg( feature = "http1" ) ]
437
- ProtoClient :: H1 ( ref mut h1) => h1. poll_without_shutdown ( cx) ,
457
+ ProtoClient :: H1 { ref mut h1 } => h1. poll_without_shutdown ( cx) ,
438
458
#[ cfg( feature = "http2" ) ]
439
- ProtoClient :: H2 ( ref mut h2, _) => Pin :: new ( h2) . poll ( cx) . map_ok ( |_| ( ) ) ,
459
+ ProtoClient :: H2 { ref mut h2, .. } => Pin :: new ( h2) . poll ( cx) . map_ok ( |_| ( ) ) ,
460
+
461
+ #[ cfg( not( feature = "http1" ) ) ]
462
+ ProtoClient :: H1 { ref mut h1 } => match h1. 0 { } ,
463
+ #[ cfg( not( feature = "http2" ) ) ]
464
+ ProtoClient :: H2 { ref mut h2, .. } => match h2. 0 { } ,
440
465
}
441
466
}
442
467
@@ -465,7 +490,7 @@ where
465
490
proto:: Dispatched :: Shutdown => Poll :: Ready ( Ok ( ( ) ) ) ,
466
491
#[ cfg( feature = "http1" ) ]
467
492
proto:: Dispatched :: Upgrade ( pending) => match self . inner . take ( ) {
468
- Some ( ProtoClient :: H1 ( h1 ) ) => {
493
+ Some ( ProtoClient :: H1 { h1 } ) => {
469
494
let ( io, buf, _) = h1. into_inner ( ) ;
470
495
pending. fulfill ( Upgraded :: new ( io, buf) ) ;
471
496
Poll :: Ready ( Ok ( ( ) ) )
@@ -756,14 +781,14 @@ impl Builder {
756
781
}
757
782
let cd = proto:: h1:: dispatch:: Client :: new ( rx) ;
758
783
let dispatch = proto:: h1:: Dispatcher :: new ( cd, conn) ;
759
- ProtoClient :: H1 ( dispatch)
784
+ ProtoClient :: H1 { h1 : dispatch }
760
785
}
761
786
#[ cfg( feature = "http2" ) ]
762
787
Proto :: Http2 => {
763
788
let h2 =
764
789
proto:: h2:: client:: handshake ( io, rx, & opts. h2_builder , opts. exec . clone ( ) )
765
790
. await ?;
766
- ProtoClient :: H2 ( h2 , PhantomData )
791
+ ProtoClient :: H2 { h2 }
767
792
}
768
793
} ;
769
794
@@ -817,9 +842,14 @@ where
817
842
fn poll ( self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
818
843
match self . project ( ) {
819
844
#[ cfg( feature = "http1" ) ]
820
- ProtoClientProj :: H1 ( c ) => c . poll ( cx) ,
845
+ ProtoClientProj :: H1 { h1 } => h1 . poll ( cx) ,
821
846
#[ cfg( feature = "http2" ) ]
822
- ProtoClientProj :: H2 ( c, _) => c. poll ( cx) ,
847
+ ProtoClientProj :: H2 { h2, .. } => h2. poll ( cx) ,
848
+
849
+ #[ cfg( not( feature = "http1" ) ) ]
850
+ ProtoClientProj :: H1 { h1 } => match h1. 0 { } ,
851
+ #[ cfg( not( feature = "http2" ) ) ]
852
+ ProtoClientProj :: H2 { h2, .. } => match h2. 0 { } ,
823
853
}
824
854
}
825
855
}
0 commit comments