11#[ cfg( feature = "http2" ) ]
22use std:: future:: Future ;
33
4+ #[ cfg( feature = "http2" ) ]
45use http:: { Request , Response } ;
6+ #[ cfg( feature = "http2" ) ]
57use http_body:: Body ;
8+ #[ cfg( feature = "http2" ) ]
69use pin_project_lite:: pin_project;
710use tokio:: sync:: { mpsc, oneshot} ;
811
9- use crate :: {
10- body:: Incoming ,
11- common:: { task, Poll } ,
12- } ;
12+ use crate :: common:: { task, Poll } ;
1313#[ cfg( feature = "http2" ) ]
14- use crate :: { common:: Pin , proto:: h2:: client:: ResponseFutMap } ;
14+ use crate :: { body :: Incoming , common:: Pin , proto:: h2:: client:: ResponseFutMap } ;
1515
1616#[ cfg( test) ]
1717pub ( crate ) type RetryPromise < T , U > = oneshot:: Receiver < Result < U , ( crate :: Error , Option < T > ) > > ;
@@ -21,6 +21,7 @@ pub(crate) fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
2121 let ( tx, rx) = mpsc:: unbounded_channel ( ) ;
2222 let ( giver, taker) = want:: new ( ) ;
2323 let tx = Sender {
24+ #[ cfg( feature = "http1" ) ]
2425 buffered_once : false ,
2526 giver,
2627 inner : tx,
@@ -37,6 +38,7 @@ pub(crate) struct Sender<T, U> {
3738 /// One message is always allowed, even if the Receiver hasn't asked
3839 /// for it yet. This boolean keeps track of whether we've sent one
3940 /// without notice.
41+ #[ cfg( feature = "http1" ) ]
4042 buffered_once : bool ,
4143 /// The Giver helps watch that the the Receiver side has been polled
4244 /// when the queue is empty. This helps us know when a request and
@@ -59,20 +61,24 @@ pub(crate) struct UnboundedSender<T, U> {
5961}
6062
6163impl < T , U > Sender < T , U > {
64+ #[ cfg( feature = "http1" ) ]
6265 pub ( crate ) fn poll_ready ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < crate :: Result < ( ) > > {
6366 self . giver
6467 . poll_want ( cx)
6568 . map_err ( |_| crate :: Error :: new_closed ( ) )
6669 }
6770
71+ #[ cfg( feature = "http1" ) ]
6872 pub ( crate ) fn is_ready ( & self ) -> bool {
6973 self . giver . is_wanting ( )
7074 }
7175
76+ #[ cfg( feature = "http1" ) ]
7277 pub ( crate ) fn is_closed ( & self ) -> bool {
7378 self . giver . is_canceled ( )
7479 }
7580
81+ #[ cfg( feature = "http1" ) ]
7682 fn can_send ( & mut self ) -> bool {
7783 if self . giver . give ( ) || !self . buffered_once {
7884 // If the receiver is ready *now*, then of course we can send.
@@ -98,6 +104,7 @@ impl<T, U> Sender<T, U> {
98104 . map_err ( |mut e| ( e. 0 ) . 0 . take ( ) . expect ( "envelope not dropped" ) . 0 )
99105 }
100106
107+ #[ cfg( feature = "http1" ) ]
101108 pub ( crate ) fn send ( & mut self , val : T ) -> Result < Promise < U > , T > {
102109 if !self . can_send ( ) {
103110 return Err ( val) ;
0 commit comments