@@ -213,59 +213,44 @@ 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 ( ) , Scheme :: Https )
225
+ connect ( Allow :: Any , Scheme :: Https )
225
226
. await
226
227
. unwrap ( ) ;
227
228
}
228
229
229
230
#[ tokio:: test]
230
231
async fn connects_http ( ) {
231
- oneshot ( https_or_http_connector ( ) , Scheme :: Http )
232
+ connect ( Allow :: Https , Scheme :: Http )
232
233
. await
233
234
. unwrap ( ) ;
234
235
}
235
236
236
237
#[ tokio:: test]
237
238
async fn connects_https_only ( ) {
238
- oneshot ( https_only_connector ( ) , Scheme :: Https )
239
+ connect ( Allow :: Any , Scheme :: Https )
239
240
. await
240
241
. unwrap ( ) ;
241
242
}
242
243
243
244
#[ tokio:: test]
244
245
async fn enforces_https_only ( ) {
245
- let message = oneshot ( https_only_connector ( ) , Scheme :: Http )
246
+ let message = connect ( Allow :: Https , Scheme :: Http )
246
247
. await
247
248
. unwrap_err ( )
248
249
. to_string ( ) ;
249
250
250
251
assert_eq ! ( message, "unsupported scheme http" ) ;
251
252
}
252
253
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
254
fn tls_config ( ) -> rustls:: ClientConfig {
270
255
#[ cfg( feature = "rustls-platform-verifier" ) ]
271
256
return rustls:: ClientConfig :: builder ( )
@@ -284,10 +269,18 @@ mod tests {
284
269
. with_no_client_auth ( ) ;
285
270
}
286
271
287
- async fn oneshot < S : Service < Uri > > (
288
- mut service : S ,
272
+ async fn connect (
273
+ allow : Allow ,
289
274
scheme : Scheme ,
290
- ) -> Result < S :: Response , S :: Error > {
275
+ ) -> Result < MaybeHttpsStream < TokioIo < TcpStream > > , BoxError > {
276
+ let builder = HttpsConnectorBuilder :: new ( ) . with_tls_config ( tls_config ( ) ) ;
277
+ let mut service = match allow {
278
+ Allow :: Https => builder. https_only ( ) ,
279
+ Allow :: Any => builder. https_or_http ( ) ,
280
+ }
281
+ . enable_http1 ( )
282
+ . build ( ) ;
283
+
291
284
poll_fn ( |cx| service. poll_ready ( cx) ) . await ?;
292
285
service
293
286
. call ( Uri :: from_static ( match scheme {
@@ -297,6 +290,11 @@ mod tests {
297
290
. await
298
291
}
299
292
293
+ enum Allow {
294
+ Https ,
295
+ Any ,
296
+ }
297
+
300
298
enum Scheme {
301
299
Https ,
302
300
Http ,
0 commit comments