@@ -174,16 +174,22 @@ impl ConnectorBuilder<WantsProtocols1> {
174
174
} )
175
175
}
176
176
177
- /// Enable all HTTP versions
177
+ /// Enable all HTTP versions built into this library (enabled with Cargo features)
178
178
///
179
- /// For now, this enables both HTTP 1 and 2. In the future, other supported versions
180
- /// will be enabled as well.
181
- #[ cfg( all( feature = "http1" , feature = "http2" ) ) ]
179
+ /// For now, this could enable both HTTP 1 and 2, depending on active features.
180
+ /// In the future, other supported versions will be enabled as well.
181
+ #[ cfg( feature = "http2" ) ]
182
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
182
183
pub fn enable_all_versions ( mut self ) -> ConnectorBuilder < WantsProtocols3 > {
183
- self . 0 . tls_config . alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
184
+ #[ cfg( feature = "http1" ) ]
185
+ let alpn_protocols = vec ! [ b"h2" . to_vec( ) , b"http/1.1" . to_vec( ) ] ;
186
+ #[ cfg( not( feature = "http1" ) ) ]
187
+ let alpn_protocols = vec ! [ b"h2" . to_vec( ) ] ;
188
+
189
+ self . 0 . tls_config . alpn_protocols = alpn_protocols;
184
190
ConnectorBuilder ( WantsProtocols3 {
185
191
inner : self . 0 ,
186
- enable_http1 : true ,
192
+ enable_http1 : cfg ! ( feature = "http1" ) ,
187
193
} )
188
194
}
189
195
@@ -326,7 +332,7 @@ mod tests {
326
332
. build ( ) ;
327
333
assert_eq ! ( & connector. tls_config. alpn_protocols, & [ b"h2" . to_vec( ) ] ) ;
328
334
let connector = super :: ConnectorBuilder :: new ( )
329
- . with_tls_config ( tls_config)
335
+ . with_tls_config ( tls_config. clone ( ) )
330
336
. https_only ( )
331
337
. enable_http1 ( )
332
338
. enable_http2 ( )
@@ -335,5 +341,36 @@ mod tests {
335
341
& connector. tls_config. alpn_protocols,
336
342
& [ b"h2" . to_vec( ) , b"http/1.1" . to_vec( ) ]
337
343
) ;
344
+ let connector = super :: ConnectorBuilder :: new ( )
345
+ . with_tls_config ( tls_config)
346
+ . https_only ( )
347
+ . enable_all_versions ( )
348
+ . build ( ) ;
349
+ assert_eq ! (
350
+ & connector. tls_config. alpn_protocols,
351
+ & [ b"h2" . to_vec( ) , b"http/1.1" . to_vec( ) ]
352
+ ) ;
353
+ }
354
+
355
+ #[ test]
356
+ #[ cfg( all( not( feature = "http1" ) , feature = "http2" ) ) ]
357
+ fn test_alpn_http2 ( ) {
358
+ let roots = rustls:: RootCertStore :: empty ( ) ;
359
+ let tls_config = rustls:: ClientConfig :: builder ( )
360
+ . with_safe_defaults ( )
361
+ . with_root_certificates ( roots)
362
+ . with_no_client_auth ( ) ;
363
+ let connector = super :: ConnectorBuilder :: new ( )
364
+ . with_tls_config ( tls_config. clone ( ) )
365
+ . https_only ( )
366
+ . enable_http2 ( )
367
+ . build ( ) ;
368
+ assert_eq ! ( & connector. tls_config. alpn_protocols, & [ b"h2" . to_vec( ) ] ) ;
369
+ let connector = super :: ConnectorBuilder :: new ( )
370
+ . with_tls_config ( tls_config)
371
+ . https_only ( )
372
+ . enable_all_versions ( )
373
+ . build ( ) ;
374
+ assert_eq ! ( & connector. tls_config. alpn_protocols, & [ b"h2" . to_vec( ) ] ) ;
338
375
}
339
376
}
0 commit comments