11use std:: fmt;
2+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
23use std:: future:: Future ;
34use std:: pin:: Pin ;
45use std:: task:: { Context , Poll } ;
56
67use bytes:: Bytes ;
78use futures_channel:: mpsc;
89use futures_channel:: oneshot;
10+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
911use futures_util:: { stream:: FusedStream , Stream } ; // for mpsc::Receiver
1012use http:: HeaderMap ;
1113use http_body:: { Body , Frame , SizeHint } ;
1214
15+ #[ cfg( all(
16+ any( feature = "http1" , feature = "http2" ) ,
17+ any( feature = "client" , feature = "server" )
18+ ) ) ]
1319use super :: DecodedLength ;
1420use crate :: common:: watch;
1521#[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
@@ -39,8 +45,8 @@ pub struct Incoming {
3945}
4046
4147enum Kind {
42- #[ allow( dead_code) ]
4348 Empty ,
49+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
4450 Chan {
4551 content_length : DecodedLength ,
4652 want_tx : watch:: Sender ,
@@ -86,11 +92,12 @@ impl Incoming {
8692 ///
8793 /// Useful when wanting to stream chunks from another thread.
8894 #[ inline]
89- #[ allow ( unused ) ]
95+ #[ cfg ( test ) ]
9096 pub ( crate ) fn channel ( ) -> ( Sender , Incoming ) {
9197 Self :: new_channel ( DecodedLength :: CHUNKED , /*wanter =*/ false )
9298 }
9399
100+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
94101 pub ( crate ) fn new_channel ( content_length : DecodedLength , wanter : bool ) -> ( Sender , Incoming ) {
95102 let ( data_tx, data_rx) = mpsc:: channel ( 0 ) ;
96103 let ( trailers_tx, trailers_rx) = oneshot:: channel ( ) ;
@@ -171,11 +178,26 @@ impl Body for Incoming {
171178 type Error = crate :: Error ;
172179
173180 fn poll_frame (
181+ #[ cfg_attr(
182+ not( all(
183+ any( feature = "http1" , feature = "http2" ) ,
184+ any( feature = "client" , feature = "server" )
185+ ) ) ,
186+ allow( unused_mut)
187+ ) ]
174188 mut self : Pin < & mut Self > ,
189+ #[ cfg_attr(
190+ not( all(
191+ any( feature = "http1" , feature = "http2" ) ,
192+ any( feature = "client" , feature = "server" )
193+ ) ) ,
194+ allow( unused_variables)
195+ ) ]
175196 cx : & mut Context < ' _ > ,
176197 ) -> Poll < Option < Result < Frame < Self :: Data > , Self :: Error > > > {
177198 match self . kind {
178199 Kind :: Empty => Poll :: Ready ( None ) ,
200+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
179201 Kind :: Chan {
180202 content_length : ref mut len,
181203 ref mut data_rx,
@@ -247,6 +269,7 @@ impl Body for Incoming {
247269 fn is_end_stream ( & self ) -> bool {
248270 match self . kind {
249271 Kind :: Empty => true ,
272+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
250273 Kind :: Chan { content_length, .. } => content_length == DecodedLength :: ZERO ,
251274 #[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
252275 Kind :: H2 { recv : ref h2, .. } => h2. is_end_stream ( ) ,
@@ -256,6 +279,10 @@ impl Body for Incoming {
256279 }
257280
258281 fn size_hint ( & self ) -> SizeHint {
282+ #[ cfg( all(
283+ any( feature = "http1" , feature = "http2" ) ,
284+ any( feature = "client" , feature = "server" )
285+ ) ) ]
259286 macro_rules! opt_len {
260287 ( $content_length: expr) => { {
261288 let mut hint = SizeHint :: default ( ) ;
@@ -270,6 +297,7 @@ impl Body for Incoming {
270297
271298 match self . kind {
272299 Kind :: Empty => SizeHint :: with_exact ( 0 ) ,
300+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
273301 Kind :: Chan { content_length, .. } => opt_len ! ( content_length) ,
274302 #[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
275303 Kind :: H2 { content_length, .. } => opt_len ! ( content_length) ,
@@ -289,6 +317,13 @@ impl fmt::Debug for Incoming {
289317 let mut builder = f. debug_tuple ( "Body" ) ;
290318 match self . kind {
291319 Kind :: Empty => builder. field ( & Empty ) ,
320+ #[ cfg( any(
321+ all(
322+ any( feature = "http1" , feature = "http2" ) ,
323+ any( feature = "client" , feature = "server" )
324+ ) ,
325+ feature = "ffi"
326+ ) ) ]
292327 _ => builder. field ( & Streaming ) ,
293328 } ;
294329
0 commit comments