1
1
use std:: fmt;
2
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
2
3
use std:: future:: Future ;
3
4
use std:: pin:: Pin ;
4
5
use std:: task:: { Context , Poll } ;
5
6
6
7
use bytes:: Bytes ;
7
8
use futures_channel:: mpsc;
8
9
use futures_channel:: oneshot;
10
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
9
11
use futures_util:: { stream:: FusedStream , Stream } ; // for mpsc::Receiver
10
12
use http:: HeaderMap ;
11
13
use http_body:: { Body , Frame , SizeHint } ;
12
14
15
+ #[ cfg( all(
16
+ any( feature = "http1" , feature = "http2" ) ,
17
+ any( feature = "client" , feature = "server" )
18
+ ) ) ]
13
19
use super :: DecodedLength ;
14
20
use crate :: common:: watch;
15
21
#[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
@@ -39,8 +45,8 @@ pub struct Incoming {
39
45
}
40
46
41
47
enum Kind {
42
- #[ allow( dead_code) ]
43
48
Empty ,
49
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
44
50
Chan {
45
51
content_length : DecodedLength ,
46
52
want_tx : watch:: Sender ,
@@ -86,11 +92,12 @@ impl Incoming {
86
92
///
87
93
/// Useful when wanting to stream chunks from another thread.
88
94
#[ inline]
89
- #[ allow ( unused ) ]
95
+ #[ cfg ( test ) ]
90
96
pub ( crate ) fn channel ( ) -> ( Sender , Incoming ) {
91
97
Self :: new_channel ( DecodedLength :: CHUNKED , /*wanter =*/ false )
92
98
}
93
99
100
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
94
101
pub ( crate ) fn new_channel ( content_length : DecodedLength , wanter : bool ) -> ( Sender , Incoming ) {
95
102
let ( data_tx, data_rx) = mpsc:: channel ( 0 ) ;
96
103
let ( trailers_tx, trailers_rx) = oneshot:: channel ( ) ;
@@ -171,11 +178,26 @@ impl Body for Incoming {
171
178
type Error = crate :: Error ;
172
179
173
180
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
+ ) ]
174
188
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
+ ) ]
175
196
cx : & mut Context < ' _ > ,
176
197
) -> Poll < Option < Result < Frame < Self :: Data > , Self :: Error > > > {
177
198
match self . kind {
178
199
Kind :: Empty => Poll :: Ready ( None ) ,
200
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
179
201
Kind :: Chan {
180
202
content_length : ref mut len,
181
203
ref mut data_rx,
@@ -247,6 +269,7 @@ impl Body for Incoming {
247
269
fn is_end_stream ( & self ) -> bool {
248
270
match self . kind {
249
271
Kind :: Empty => true ,
272
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
250
273
Kind :: Chan { content_length, .. } => content_length == DecodedLength :: ZERO ,
251
274
#[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
252
275
Kind :: H2 { recv : ref h2, .. } => h2. is_end_stream ( ) ,
@@ -256,6 +279,10 @@ impl Body for Incoming {
256
279
}
257
280
258
281
fn size_hint ( & self ) -> SizeHint {
282
+ #[ cfg( all(
283
+ any( feature = "http1" , feature = "http2" ) ,
284
+ any( feature = "client" , feature = "server" )
285
+ ) ) ]
259
286
macro_rules! opt_len {
260
287
( $content_length: expr) => { {
261
288
let mut hint = SizeHint :: default ( ) ;
@@ -270,6 +297,7 @@ impl Body for Incoming {
270
297
271
298
match self . kind {
272
299
Kind :: Empty => SizeHint :: with_exact ( 0 ) ,
300
+ #[ cfg( all( feature = "http1" , any( feature = "client" , feature = "server" ) ) ) ]
273
301
Kind :: Chan { content_length, .. } => opt_len ! ( content_length) ,
274
302
#[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
275
303
Kind :: H2 { content_length, .. } => opt_len ! ( content_length) ,
@@ -289,6 +317,13 @@ impl fmt::Debug for Incoming {
289
317
let mut builder = f. debug_tuple ( "Body" ) ;
290
318
match self . kind {
291
319
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
+ ) ) ]
292
327
_ => builder. field ( & Streaming ) ,
293
328
} ;
294
329
0 commit comments