@@ -213,59 +213,38 @@ mod tests {
213
213
use std:: future:: poll_fn;
214
214
215
215
use http:: Uri ;
216
- use hyper_util:: client:: legacy:: connect:: HttpConnector ;
216
+ use hyper_util:: rt:: TokioIo ;
217
+ use tokio:: net:: TcpStream ;
217
218
use tower_service:: Service ;
218
219
219
- use super :: HttpsConnector ;
220
- use crate :: { ConfigBuilderExt , HttpsConnectorBuilder } ;
220
+ use super :: * ;
221
+ use crate :: { ConfigBuilderExt , HttpsConnectorBuilder , MaybeHttpsStream } ;
221
222
222
223
#[ tokio:: test]
223
224
async fn connects_https ( ) {
224
- oneshot ( https_or_http_connector ( ) , true )
225
- . await
226
- . unwrap ( ) ;
225
+ connect ( false , true ) . await . unwrap ( ) ;
227
226
}
228
227
229
228
#[ tokio:: test]
230
229
async fn connects_http ( ) {
231
- oneshot ( https_or_http_connector ( ) , false )
232
- . await
233
- . unwrap ( ) ;
230
+ connect ( false , false ) . await . unwrap ( ) ;
234
231
}
235
232
236
233
#[ tokio:: test]
237
234
async fn connects_https_only ( ) {
238
- oneshot ( https_only_connector ( ) , true )
239
- . await
240
- . unwrap ( ) ;
235
+ connect ( true , true ) . await . unwrap ( ) ;
241
236
}
242
237
243
238
#[ tokio:: test]
244
239
async fn enforces_https_only ( ) {
245
- let message = oneshot ( https_only_connector ( ) , false )
240
+ let message = connect ( true , false )
246
241
. await
247
242
. unwrap_err ( )
248
243
. to_string ( ) ;
249
244
250
245
assert_eq ! ( message, "unsupported scheme http" ) ;
251
246
}
252
247
253
- fn https_or_http_connector ( ) -> HttpsConnector < HttpConnector > {
254
- HttpsConnectorBuilder :: new ( )
255
- . with_tls_config ( tls_config ( ) )
256
- . https_or_http ( )
257
- . enable_http1 ( )
258
- . build ( )
259
- }
260
-
261
- fn https_only_connector ( ) -> HttpsConnector < HttpConnector > {
262
- HttpsConnectorBuilder :: new ( )
263
- . with_tls_config ( tls_config ( ) )
264
- . https_only ( )
265
- . enable_http1 ( )
266
- . build ( )
267
- }
268
-
269
248
fn tls_config ( ) -> rustls:: ClientConfig {
270
249
#[ cfg( feature = "rustls-platform-verifier" ) ]
271
250
return rustls:: ClientConfig :: builder ( )
@@ -284,10 +263,18 @@ mod tests {
284
263
. with_no_client_auth ( ) ;
285
264
}
286
265
287
- async fn oneshot < S : Service < Uri > > (
288
- mut service : S ,
266
+ async fn connect (
267
+ https_only : bool ,
289
268
https : bool ,
290
- ) -> Result < S :: Response , S :: Error > {
269
+ ) -> Result < MaybeHttpsStream < TokioIo < TcpStream > > , BoxError > {
270
+ let builder = HttpsConnectorBuilder :: new ( ) . with_tls_config ( tls_config ( ) ) ;
271
+ let mut service = match https_only {
272
+ true => builder. https_only ( ) ,
273
+ false => builder. https_or_http ( ) ,
274
+ }
275
+ . enable_http1 ( )
276
+ . build ( ) ;
277
+
291
278
poll_fn ( |cx| service. poll_ready ( cx) ) . await ?;
292
279
service
293
280
. call ( Uri :: from_static ( match https {
0 commit comments