@@ -80,12 +80,16 @@ impl<E> Builder<E> {
8080 /// # Example
8181 ///
8282 /// ```
83+ /// # #[cfg(all(feature = "tokio", feature = "http2"))]
84+ /// # fn run() {
8385 /// use hyper_util::{
8486 /// rt::TokioExecutor,
8587 /// server::conn::auto,
8688 /// };
8789 ///
8890 /// auto::Builder::new(TokioExecutor::new());
91+ /// # }
92+ /// # fn main() {}
8993 /// ```
9094 pub fn new ( executor : E ) -> Self {
9195 Self {
@@ -179,7 +183,7 @@ impl<E> Builder<E> {
179183 /// auto::Builder::new(TokioExecutor::new())
180184 /// .title_case_headers(true);
181185 /// ```
182- #[ cfg( feature = "http1" ) ]
186+ #[ cfg( all ( feature = "tokio" , feature = " http1") ) ]
183187 pub fn title_case_headers ( mut self , enabled : bool ) -> Self {
184188 self . http1 . title_case_headers ( enabled) ;
185189 self
@@ -203,7 +207,7 @@ impl<E> Builder<E> {
203207 /// auto::Builder::new(TokioExecutor::new())
204208 /// .preserve_header_case(true);
205209 /// ```
206- #[ cfg( feature = "http1" ) ]
210+ #[ cfg( all ( feature = "tokio" , feature = " http1") ) ]
207211 pub fn preserve_header_case ( mut self , enabled : bool ) -> Self {
208212 self . http1 . preserve_header_case ( enabled) ;
209213 self
@@ -1124,17 +1128,24 @@ impl<E> Http2Builder<'_, E> {
11241128 }
11251129}
11261130
1127- #[ cfg( test) ]
1131+ #[ cfg( all ( test, feature = "tokio" ) ) ]
11281132mod tests {
1129- use crate :: {
1130- rt:: { TokioExecutor , TokioIo } ,
1131- server:: conn:: auto,
1132- } ;
1133+ use crate :: rt:: { TokioExecutor , TokioIo } ;
1134+ use crate :: server:: conn:: auto;
11331135 use http:: { Request , Response } ;
1136+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
11341137 use http_body:: Body ;
1135- use http_body_util:: { BodyExt , Empty , Full } ;
1136- use hyper:: { body, body:: Bytes , client, service:: service_fn} ;
1137- use std:: { convert:: Infallible , error:: Error as StdError , net:: SocketAddr , time:: Duration } ;
1138+ use http_body_util:: Full ;
1139+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
1140+ use http_body_util:: { BodyExt , Empty } ;
1141+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
1142+ use hyper:: client;
1143+ use hyper:: service:: service_fn;
1144+ use hyper:: { body, body:: Bytes } ;
1145+ use std:: convert:: Infallible ;
1146+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
1147+ use std:: error:: Error as StdError ;
1148+ use std:: { net:: SocketAddr , time:: Duration } ;
11381149 use tokio:: {
11391150 net:: { TcpListener , TcpStream } ,
11401151 pin,
@@ -1143,6 +1154,7 @@ mod tests {
11431154 const BODY : & [ u8 ] = b"Hello, world!" ;
11441155
11451156 #[ test]
1157+ #[ cfg( all( feature = "http1" , feature = "http2" ) ) ]
11461158 fn configuration ( ) {
11471159 // One liner.
11481160 auto:: Builder :: new ( TokioExecutor :: new ( ) )
@@ -1184,8 +1196,8 @@ mod tests {
11841196 . http1_only ( ) ;
11851197 }
11861198
1187- #[ cfg( not( miri) ) ]
11881199 #[ tokio:: test]
1200+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
11891201 async fn http1 ( ) {
11901202 let addr = start_server ( false , false ) . await ;
11911203 let mut sender = connect_h1 ( addr) . await ;
@@ -1200,8 +1212,8 @@ mod tests {
12001212 assert_eq ! ( body, BODY ) ;
12011213 }
12021214
1203- #[ cfg( not( miri) ) ]
12041215 #[ tokio:: test]
1216+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
12051217 async fn http2 ( ) {
12061218 let addr = start_server ( false , false ) . await ;
12071219 let mut sender = connect_h2 ( addr) . await ;
@@ -1216,8 +1228,8 @@ mod tests {
12161228 assert_eq ! ( body, BODY ) ;
12171229 }
12181230
1219- #[ cfg( not( miri) ) ]
12201231 #[ tokio:: test]
1232+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
12211233 async fn http2_only ( ) {
12221234 let addr = start_server ( false , true ) . await ;
12231235 let mut sender = connect_h2 ( addr) . await ;
@@ -1232,8 +1244,8 @@ mod tests {
12321244 assert_eq ! ( body, BODY ) ;
12331245 }
12341246
1235- #[ cfg( not( miri) ) ]
12361247 #[ tokio:: test]
1248+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
12371249 async fn http2_only_fail_if_client_is_http1 ( ) {
12381250 let addr = start_server ( false , true ) . await ;
12391251 let mut sender = connect_h1 ( addr) . await ;
@@ -1244,8 +1256,8 @@ mod tests {
12441256 . expect_err ( "should fail" ) ;
12451257 }
12461258
1247- #[ cfg( not( miri) ) ]
12481259 #[ tokio:: test]
1260+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
12491261 async fn http1_only ( ) {
12501262 let addr = start_server ( true , false ) . await ;
12511263 let mut sender = connect_h1 ( addr) . await ;
@@ -1260,8 +1272,8 @@ mod tests {
12601272 assert_eq ! ( body, BODY ) ;
12611273 }
12621274
1263- #[ cfg( not( miri) ) ]
12641275 #[ tokio:: test]
1276+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
12651277 async fn http1_only_fail_if_client_is_http2 ( ) {
12661278 let addr = start_server ( true , false ) . await ;
12671279 let mut sender = connect_h2 ( addr) . await ;
@@ -1306,6 +1318,7 @@ mod tests {
13061318 assert_eq ! ( connection_error. kind( ) , std:: io:: ErrorKind :: Interrupted ) ;
13071319 }
13081320
1321+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
13091322 async fn connect_h1 < B > ( addr : SocketAddr ) -> client:: conn:: http1:: SendRequest < B >
13101323 where
13111324 B : Body + Send + ' static ,
@@ -1320,6 +1333,7 @@ mod tests {
13201333 sender
13211334 }
13221335
1336+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
13231337 async fn connect_h2 < B > ( addr : SocketAddr ) -> client:: conn:: http2:: SendRequest < B >
13241338 where
13251339 B : Body + Unpin + Send + ' static ,
@@ -1337,6 +1351,7 @@ mod tests {
13371351 sender
13381352 }
13391353
1354+ #[ cfg( all( feature = "http1" , feature = "http2" , not( miri) ) ) ]
13401355 async fn start_server ( h1_only : bool , h2_only : bool ) -> SocketAddr {
13411356 let addr: SocketAddr = ( [ 127 , 0 , 0 , 1 ] , 0 ) . into ( ) ;
13421357 let listener = TcpListener :: bind ( addr) . await . unwrap ( ) ;
0 commit comments