43
43
//! # }
44
44
//! ```
45
45
46
- use std:: error:: Error as StdError ;
47
- use std:: fmt;
48
- #[ cfg( not( all( feature = "http1" , feature = "http2" ) ) ) ]
46
+ #[ cfg( all(
47
+ any( feature = "http1" , feature = "http2" ) ,
48
+ not( all( feature = "http1" , feature = "http2" ) )
49
+ ) ) ]
49
50
use std:: marker:: PhantomData ;
50
51
#[ cfg( feature = "tcp" ) ]
51
52
use std:: net:: SocketAddr ;
52
53
#[ cfg( all( feature = "runtime" , feature = "http2" ) ) ]
53
54
use std:: time:: Duration ;
54
55
55
- use bytes:: Bytes ;
56
- use pin_project_lite:: pin_project;
57
- use tokio:: io:: { AsyncRead , AsyncWrite } ;
58
- use tracing:: trace;
59
-
60
- use super :: accept:: Accept ;
61
- use crate :: body:: { Body , HttpBody } ;
62
- use crate :: common:: exec:: { ConnStreamExec , Exec , NewSvcExec } ;
63
56
#[ cfg( feature = "http2" ) ]
64
57
use crate :: common:: io:: Rewind ;
65
- #[ cfg( not( all( feature = "http1" , feature = "http2" ) ) ) ]
66
- use crate :: common:: Never ;
67
- use crate :: common:: { task, Future , Pin , Poll , Unpin } ;
68
58
#[ cfg( all( feature = "http1" , feature = "http2" ) ) ]
69
59
use crate :: error:: { Kind , Parse } ;
70
- use crate :: proto;
71
- use crate :: service:: { HttpService , MakeServiceRef } ;
72
60
#[ cfg( feature = "http1" ) ]
73
61
use crate :: upgrade:: Upgraded ;
74
62
75
- use self :: spawn_all:: NewSvcTask ;
76
- pub ( super ) use self :: spawn_all:: { NoopWatcher , Watcher } ;
77
- pub ( super ) use self :: upgrades:: UpgradeableConnection ;
63
+ cfg_feature ! {
64
+ #![ any( feature = "http1" , feature = "http2" ) ]
65
+
66
+ use std:: error:: Error as StdError ;
67
+ use std:: fmt;
68
+
69
+ use bytes:: Bytes ;
70
+ use pin_project_lite:: pin_project;
71
+ use tokio:: io:: { AsyncRead , AsyncWrite } ;
72
+ use tracing:: trace;
73
+
74
+ use super :: accept:: Accept ;
75
+ use crate :: body:: { Body , HttpBody } ;
76
+ use crate :: common:: { task, Future , Pin , Poll , Unpin } ;
77
+ #[ cfg( not( all( feature = "http1" , feature = "http2" ) ) ) ]
78
+ use crate :: common:: Never ;
79
+ use crate :: common:: exec:: { ConnStreamExec , Exec , NewSvcExec } ;
80
+ use crate :: proto;
81
+ use crate :: service:: { HttpService , MakeServiceRef } ;
82
+ use self :: spawn_all:: NewSvcTask ;
83
+
84
+ pub ( super ) use self :: spawn_all:: { NoopWatcher , Watcher } ;
85
+ pub ( super ) use self :: upgrades:: UpgradeableConnection ;
86
+ }
78
87
79
88
#[ cfg( feature = "tcp" ) ]
80
89
pub use super :: tcp:: { AddrIncoming , AddrStream } ;
@@ -86,6 +95,8 @@ pub use super::tcp::{AddrIncoming, AddrStream};
86
95
/// If you don't have need to manage connections yourself, consider using the
87
96
/// higher-level [Server](super) API.
88
97
#[ derive( Clone , Debug ) ]
98
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
99
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "http1" , feature = "http2" ) ) ) ) ]
89
100
pub struct Http < E = Exec > {
90
101
exec : E ,
91
102
h1_half_close : bool ,
@@ -100,6 +111,7 @@ pub struct Http<E = Exec> {
100
111
}
101
112
102
113
/// The internal mode of HTTP protocol which indicates the behavior when a parse error occurs.
114
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
103
115
#[ derive( Clone , Debug , PartialEq ) ]
104
116
enum ConnectionMode {
105
117
/// Always use HTTP/1 and do not upgrade when a parse error occurs.
@@ -113,6 +125,7 @@ enum ConnectionMode {
113
125
Fallback ,
114
126
}
115
127
128
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
116
129
pin_project ! {
117
130
/// A stream mapping incoming IOs to new services.
118
131
///
@@ -127,13 +140,15 @@ pin_project! {
127
140
}
128
141
}
129
142
143
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
130
144
pin_project ! {
131
145
/// A future building a new `Service` to a `Connection`.
132
146
///
133
147
/// Wraps the future returned from `MakeService` into one that returns
134
148
/// a `Connection`.
135
149
#[ must_use = "futures do nothing unless polled" ]
136
150
#[ derive( Debug ) ]
151
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "http1" , feature = "http2" ) ) ) ) ]
137
152
pub struct Connecting <I , F , E = Exec > {
138
153
#[ pin]
139
154
future: F ,
@@ -142,6 +157,7 @@ pin_project! {
142
157
}
143
158
}
144
159
160
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
145
161
pin_project ! {
146
162
#[ must_use = "futures do nothing unless polled" ]
147
163
#[ derive( Debug ) ]
@@ -154,11 +170,13 @@ pin_project! {
154
170
}
155
171
}
156
172
173
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
157
174
pin_project ! {
158
175
/// A future binding a connection with a Service.
159
176
///
160
177
/// Polling this future will drive HTTP forward.
161
178
#[ must_use = "futures do nothing unless polled" ]
179
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "http1" , feature = "http2" ) ) ) ) ]
162
180
pub struct Connection <T , S , E = Exec >
163
181
where
164
182
S : HttpService <Body >,
@@ -172,18 +190,19 @@ pin_project! {
172
190
type Http1Dispatcher < T , B , S > =
173
191
proto:: h1:: Dispatcher < proto:: h1:: dispatch:: Server < S , Body > , B , T , proto:: ServerTransaction > ;
174
192
175
- #[ cfg( not( feature = "http1" ) ) ]
193
+ #[ cfg( all ( not( feature = "http1" ) , feature = "http2 ") ) ]
176
194
type Http1Dispatcher < T , B , S > = ( Never , PhantomData < ( T , Box < Pin < B > > , Box < Pin < S > > ) > ) ;
177
195
178
196
#[ cfg( feature = "http2" ) ]
179
197
type Http2Server < T , B , S , E > = proto:: h2:: Server < Rewind < T > , S , B , E > ;
180
198
181
- #[ cfg( not( feature = "http2" ) ) ]
199
+ #[ cfg( all ( not( feature = "http2" ) , feature = "http1 ") ) ]
182
200
type Http2Server < T , B , S , E > = (
183
201
Never ,
184
202
PhantomData < ( T , Box < Pin < S > > , Box < Pin < B > > , Box < Pin < E > > ) > ,
185
203
) ;
186
204
205
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
187
206
pin_project ! {
188
207
#[ project = ProtoServerProj ]
189
208
pub ( super ) enum ProtoServer <T , B , S , E = Exec >
@@ -209,7 +228,10 @@ enum Fallback<E> {
209
228
Http1Only ,
210
229
}
211
230
212
- #[ cfg( not( all( feature = "http1" , feature = "http2" ) ) ) ]
231
+ #[ cfg( all(
232
+ any( feature = "http1" , feature = "http2" ) ,
233
+ not( all( feature = "http1" , feature = "http2" ) )
234
+ ) ) ]
213
235
type Fallback < E > = PhantomData < E > ;
214
236
215
237
#[ cfg( all( feature = "http1" , feature = "http2" ) ) ]
@@ -230,6 +252,8 @@ impl<E> Unpin for Fallback<E> {}
230
252
/// This allows taking apart a `Connection` at a later time, in order to
231
253
/// reclaim the IO object, and additional related pieces.
232
254
#[ derive( Debug ) ]
255
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
256
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "http1" , feature = "http2" ) ) ) ) ]
233
257
pub struct Parts < T , S > {
234
258
/// The original IO object used in the handshake.
235
259
pub io : T ,
@@ -249,6 +273,7 @@ pub struct Parts<T, S> {
249
273
250
274
// ===== impl Http =====
251
275
276
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
252
277
impl Http {
253
278
/// Creates a new instance of the HTTP protocol, ready to spawn a server or
254
279
/// start accepting connections.
@@ -268,6 +293,7 @@ impl Http {
268
293
}
269
294
}
270
295
296
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
271
297
impl < E > Http < E > {
272
298
/// Sets whether HTTP1 is required.
273
299
///
@@ -633,6 +659,7 @@ impl<E> Http<E> {
633
659
634
660
// ===== impl Connection =====
635
661
662
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
636
663
impl < I , B , S , E > Connection < I , S , E >
637
664
where
638
665
S : HttpService < Body , ResBody = B > ,
@@ -802,6 +829,7 @@ where
802
829
}
803
830
}
804
831
832
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
805
833
impl < I , B , S , E > Future for Connection < I , S , E >
806
834
where
807
835
S : HttpService < Body , ResBody = B > ,
@@ -848,6 +876,7 @@ where
848
876
}
849
877
}
850
878
879
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
851
880
impl < I , S > fmt:: Debug for Connection < I , S >
852
881
where
853
882
S : HttpService < Body > ,
@@ -859,6 +888,7 @@ where
859
888
860
889
// ===== impl ConnectionMode =====
861
890
891
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
862
892
impl Default for ConnectionMode {
863
893
#[ cfg( all( feature = "http1" , feature = "http2" ) ) ]
864
894
fn default ( ) -> ConnectionMode {
@@ -878,6 +908,7 @@ impl Default for ConnectionMode {
878
908
879
909
// ===== impl Serve =====
880
910
911
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
881
912
impl < I , S , E > Serve < I , S , E > {
882
913
/// Get a reference to the incoming stream.
883
914
#[ inline]
@@ -899,6 +930,7 @@ impl<I, S, E> Serve<I, S, E> {
899
930
}
900
931
}
901
932
933
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
902
934
impl < I , IO , IE , S , B , E > Serve < I , S , E >
903
935
where
904
936
I : Accept < Conn = IO , Error = IE > ,
@@ -937,6 +969,7 @@ where
937
969
938
970
// ===== impl Connecting =====
939
971
972
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
940
973
impl < I , F , S , FE , E , B > Future for Connecting < I , F , E >
941
974
where
942
975
I : AsyncRead + AsyncWrite + Unpin ,
@@ -958,19 +991,21 @@ where
958
991
959
992
// ===== impl SpawnAll =====
960
993
961
- #[ cfg( feature = "tcp" ) ]
994
+ #[ cfg( all ( feature = "tcp" , any ( feature = "http1" , feature = "http2" ) ) ) ]
962
995
impl < S , E > SpawnAll < AddrIncoming , S , E > {
963
996
pub ( super ) fn local_addr ( & self ) -> SocketAddr {
964
997
self . serve . incoming . local_addr ( )
965
998
}
966
999
}
967
1000
1001
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
968
1002
impl < I , S , E > SpawnAll < I , S , E > {
969
1003
pub ( super ) fn incoming_ref ( & self ) -> & I {
970
1004
self . serve . incoming_ref ( )
971
1005
}
972
1006
}
973
1007
1008
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
974
1009
impl < I , IO , IE , S , B , E > SpawnAll < I , S , E >
975
1010
where
976
1011
I : Accept < Conn = IO , Error = IE > ,
@@ -1008,6 +1043,7 @@ where
1008
1043
1009
1044
// ===== impl ProtoServer =====
1010
1045
1046
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1011
1047
impl < T , B , S , E > Future for ProtoServer < T , B , S , E >
1012
1048
where
1013
1049
T : AsyncRead + AsyncWrite + Unpin ,
@@ -1034,6 +1070,7 @@ where
1034
1070
}
1035
1071
}
1036
1072
1073
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1037
1074
pub ( crate ) mod spawn_all {
1038
1075
use std:: error:: Error as StdError ;
1039
1076
use tokio:: io:: { AsyncRead , AsyncWrite } ;
@@ -1177,6 +1214,7 @@ pub(crate) mod spawn_all {
1177
1214
}
1178
1215
}
1179
1216
1217
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1180
1218
mod upgrades {
1181
1219
use super :: * ;
1182
1220
0 commit comments