@@ -213,59 +213,44 @@ mod tests {
213213 use std:: future:: poll_fn;
214214
215215 use http:: Uri ;
216- use hyper_util:: client:: legacy:: connect:: HttpConnector ;
216+ use hyper_util:: rt:: TokioIo ;
217+ use tokio:: net:: TcpStream ;
217218 use tower_service:: Service ;
218219
219- use super :: HttpsConnector ;
220- use crate :: { ConfigBuilderExt , HttpsConnectorBuilder } ;
220+ use super :: * ;
221+ use crate :: { ConfigBuilderExt , HttpsConnectorBuilder , MaybeHttpsStream } ;
221222
222223 #[ tokio:: test]
223224 async fn connects_https ( ) {
224- oneshot ( https_or_http_connector ( ) , Scheme :: Https )
225+ connect ( Allow :: Any , Scheme :: Https )
225226 . await
226227 . unwrap ( ) ;
227228 }
228229
229230 #[ tokio:: test]
230231 async fn connects_http ( ) {
231- oneshot ( https_or_http_connector ( ) , Scheme :: Http )
232+ connect ( Allow :: Any , Scheme :: Http )
232233 . await
233234 . unwrap ( ) ;
234235 }
235236
236237 #[ tokio:: test]
237238 async fn connects_https_only ( ) {
238- oneshot ( https_only_connector ( ) , Scheme :: Https )
239+ connect ( Allow :: Https , Scheme :: Https )
239240 . await
240241 . unwrap ( ) ;
241242 }
242243
243244 #[ tokio:: test]
244245 async fn enforces_https_only ( ) {
245- let message = oneshot ( https_only_connector ( ) , Scheme :: Http )
246+ let message = connect ( Allow :: Https , Scheme :: Http )
246247 . await
247248 . unwrap_err ( )
248249 . to_string ( ) ;
249250
250251 assert_eq ! ( message, "unsupported scheme http" ) ;
251252 }
252253
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-
269254 fn tls_config ( ) -> rustls:: ClientConfig {
270255 #[ cfg( feature = "rustls-platform-verifier" ) ]
271256 return rustls:: ClientConfig :: builder ( )
@@ -284,10 +269,18 @@ mod tests {
284269 . with_no_client_auth ( ) ;
285270 }
286271
287- async fn oneshot < S : Service < Uri > > (
288- mut service : S ,
272+ async fn connect (
273+ allow : Allow ,
289274 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+
291284 poll_fn ( |cx| service. poll_ready ( cx) ) . await ?;
292285 service
293286 . call ( Uri :: from_static ( match scheme {
@@ -297,6 +290,11 @@ mod tests {
297290 . await
298291 }
299292
293+ enum Allow {
294+ Https ,
295+ Any ,
296+ }
297+
300298 enum Scheme {
301299 Https ,
302300 Http ,
0 commit comments