@@ -46,7 +46,7 @@ use crate::Certificate;
46
46
#[ cfg( any( feature = "native-tls" , feature = "__rustls" ) ) ]
47
47
use crate :: Identity ;
48
48
use crate :: { IntoUrl , Method , Proxy , StatusCode , Url } ;
49
- use log:: { debug, trace } ;
49
+ use log:: debug;
50
50
#[ cfg( feature = "http3" ) ]
51
51
use quinn:: TransportConfig ;
52
52
#[ cfg( feature = "http3" ) ]
@@ -80,6 +80,7 @@ pub struct ClientBuilder {
80
80
81
81
enum HttpVersionPref {
82
82
Http1 ,
83
+ #[ cfg( feature = "http2" ) ]
83
84
Http2 ,
84
85
#[ cfg( feature = "http3" ) ]
85
86
Http3 ,
@@ -126,12 +127,19 @@ struct Config {
126
127
http1_allow_obsolete_multiline_headers_in_responses : bool ,
127
128
http1_ignore_invalid_headers_in_responses : bool ,
128
129
http1_allow_spaces_after_header_name_in_responses : bool ,
130
+ #[ cfg( feature = "http2" ) ]
129
131
http2_initial_stream_window_size : Option < u32 > ,
132
+ #[ cfg( feature = "http2" ) ]
130
133
http2_initial_connection_window_size : Option < u32 > ,
134
+ #[ cfg( feature = "http2" ) ]
131
135
http2_adaptive_window : bool ,
136
+ #[ cfg( feature = "http2" ) ]
132
137
http2_max_frame_size : Option < u32 > ,
138
+ #[ cfg( feature = "http2" ) ]
133
139
http2_keep_alive_interval : Option < Duration > ,
140
+ #[ cfg( feature = "http2" ) ]
134
141
http2_keep_alive_timeout : Option < Duration > ,
142
+ #[ cfg( feature = "http2" ) ]
135
143
http2_keep_alive_while_idle : bool ,
136
144
local_address : Option < IpAddr > ,
137
145
nodelay : bool ,
@@ -211,12 +219,19 @@ impl ClientBuilder {
211
219
http1_allow_obsolete_multiline_headers_in_responses : false ,
212
220
http1_ignore_invalid_headers_in_responses : false ,
213
221
http1_allow_spaces_after_header_name_in_responses : false ,
222
+ #[ cfg( feature = "http2" ) ]
214
223
http2_initial_stream_window_size : None ,
224
+ #[ cfg( feature = "http2" ) ]
215
225
http2_initial_connection_window_size : None ,
226
+ #[ cfg( feature = "http2" ) ]
216
227
http2_adaptive_window : false ,
228
+ #[ cfg( feature = "http2" ) ]
217
229
http2_max_frame_size : None ,
230
+ #[ cfg( feature = "http2" ) ]
218
231
http2_keep_alive_interval : None ,
232
+ #[ cfg( feature = "http2" ) ]
219
233
http2_keep_alive_timeout : None ,
234
+ #[ cfg( feature = "http2" ) ]
220
235
http2_keep_alive_while_idle : false ,
221
236
local_address : None ,
222
237
nodelay : true ,
@@ -349,6 +364,7 @@ impl ClientBuilder {
349
364
HttpVersionPref :: Http1 => {
350
365
tls. request_alpns ( & [ "http/1.1" ] ) ;
351
366
}
367
+ #[ cfg( feature = "http2" ) ]
352
368
HttpVersionPref :: Http2 => {
353
369
tls. request_alpns ( & [ "h2" ] ) ;
354
370
}
@@ -541,6 +557,7 @@ impl ClientBuilder {
541
557
HttpVersionPref :: Http1 => {
542
558
tls. alpn_protocols = vec ! [ "http/1.1" . into( ) ] ;
543
559
}
560
+ #[ cfg( feature = "http2" ) ]
544
561
HttpVersionPref :: Http2 => {
545
562
tls. alpn_protocols = vec ! [ "h2" . into( ) ] ;
546
563
}
@@ -596,32 +613,36 @@ impl ClientBuilder {
596
613
597
614
let mut builder =
598
615
hyper_util:: client:: legacy:: Client :: builder ( hyper_util:: rt:: TokioExecutor :: new ( ) ) ;
599
- if matches ! ( config. http_version_pref, HttpVersionPref :: Http2 ) {
600
- builder. http2_only ( true ) ;
601
- }
602
-
603
- if let Some ( http2_initial_stream_window_size) = config. http2_initial_stream_window_size {
604
- builder. http2_initial_stream_window_size ( http2_initial_stream_window_size) ;
605
- }
606
- if let Some ( http2_initial_connection_window_size) =
607
- config. http2_initial_connection_window_size
616
+ #[ cfg( feature = "http2" ) ]
608
617
{
609
- builder. http2_initial_connection_window_size ( http2_initial_connection_window_size) ;
610
- }
611
- if config. http2_adaptive_window {
612
- builder. http2_adaptive_window ( true ) ;
613
- }
614
- if let Some ( http2_max_frame_size) = config. http2_max_frame_size {
615
- builder. http2_max_frame_size ( http2_max_frame_size) ;
616
- }
617
- if let Some ( http2_keep_alive_interval) = config. http2_keep_alive_interval {
618
- builder. http2_keep_alive_interval ( http2_keep_alive_interval) ;
619
- }
620
- if let Some ( http2_keep_alive_timeout) = config. http2_keep_alive_timeout {
621
- builder. http2_keep_alive_timeout ( http2_keep_alive_timeout) ;
622
- }
623
- if config. http2_keep_alive_while_idle {
624
- builder. http2_keep_alive_while_idle ( true ) ;
618
+ if matches ! ( config. http_version_pref, HttpVersionPref :: Http2 ) {
619
+ builder. http2_only ( true ) ;
620
+ }
621
+
622
+ if let Some ( http2_initial_stream_window_size) = config. http2_initial_stream_window_size
623
+ {
624
+ builder. http2_initial_stream_window_size ( http2_initial_stream_window_size) ;
625
+ }
626
+ if let Some ( http2_initial_connection_window_size) =
627
+ config. http2_initial_connection_window_size
628
+ {
629
+ builder. http2_initial_connection_window_size ( http2_initial_connection_window_size) ;
630
+ }
631
+ if config. http2_adaptive_window {
632
+ builder. http2_adaptive_window ( true ) ;
633
+ }
634
+ if let Some ( http2_max_frame_size) = config. http2_max_frame_size {
635
+ builder. http2_max_frame_size ( http2_max_frame_size) ;
636
+ }
637
+ if let Some ( http2_keep_alive_interval) = config. http2_keep_alive_interval {
638
+ builder. http2_keep_alive_interval ( http2_keep_alive_interval) ;
639
+ }
640
+ if let Some ( http2_keep_alive_timeout) = config. http2_keep_alive_timeout {
641
+ builder. http2_keep_alive_timeout ( http2_keep_alive_timeout) ;
642
+ }
643
+ if config. http2_keep_alive_while_idle {
644
+ builder. http2_keep_alive_while_idle ( true ) ;
645
+ }
625
646
}
626
647
627
648
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -1089,6 +1110,8 @@ impl ClientBuilder {
1089
1110
}
1090
1111
1091
1112
/// Only use HTTP/2.
1113
+ #[ cfg( feature = "http2" ) ]
1114
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1092
1115
pub fn http2_prior_knowledge ( mut self ) -> ClientBuilder {
1093
1116
self . config . http_version_pref = HttpVersionPref :: Http2 ;
1094
1117
self
@@ -1105,6 +1128,8 @@ impl ClientBuilder {
1105
1128
/// Sets the `SETTINGS_INITIAL_WINDOW_SIZE` option for HTTP2 stream-level flow control.
1106
1129
///
1107
1130
/// Default is currently 65,535 but may change internally to optimize for common uses.
1131
+ #[ cfg( feature = "http2" ) ]
1132
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1108
1133
pub fn http2_initial_stream_window_size ( mut self , sz : impl Into < Option < u32 > > ) -> ClientBuilder {
1109
1134
self . config . http2_initial_stream_window_size = sz. into ( ) ;
1110
1135
self
@@ -1113,6 +1138,8 @@ impl ClientBuilder {
1113
1138
/// Sets the max connection-level flow control for HTTP2
1114
1139
///
1115
1140
/// Default is currently 65,535 but may change internally to optimize for common uses.
1141
+ #[ cfg( feature = "http2" ) ]
1142
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1116
1143
pub fn http2_initial_connection_window_size (
1117
1144
mut self ,
1118
1145
sz : impl Into < Option < u32 > > ,
@@ -1125,6 +1152,8 @@ impl ClientBuilder {
1125
1152
///
1126
1153
/// Enabling this will override the limits set in `http2_initial_stream_window_size` and
1127
1154
/// `http2_initial_connection_window_size`.
1155
+ #[ cfg( feature = "http2" ) ]
1156
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1128
1157
pub fn http2_adaptive_window ( mut self , enabled : bool ) -> ClientBuilder {
1129
1158
self . config . http2_adaptive_window = enabled;
1130
1159
self
@@ -1133,6 +1162,8 @@ impl ClientBuilder {
1133
1162
/// Sets the maximum frame size to use for HTTP2.
1134
1163
///
1135
1164
/// Default is currently 16,384 but may change internally to optimize for common uses.
1165
+ #[ cfg( feature = "http2" ) ]
1166
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1136
1167
pub fn http2_max_frame_size ( mut self , sz : impl Into < Option < u32 > > ) -> ClientBuilder {
1137
1168
self . config . http2_max_frame_size = sz. into ( ) ;
1138
1169
self
@@ -1142,6 +1173,8 @@ impl ClientBuilder {
1142
1173
///
1143
1174
/// Pass `None` to disable HTTP2 keep-alive.
1144
1175
/// Default is currently disabled.
1176
+ #[ cfg( feature = "http2" ) ]
1177
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1145
1178
pub fn http2_keep_alive_interval (
1146
1179
mut self ,
1147
1180
interval : impl Into < Option < Duration > > ,
@@ -1155,6 +1188,8 @@ impl ClientBuilder {
1155
1188
/// If the ping is not acknowledged within the timeout, the connection will be closed.
1156
1189
/// Does nothing if `http2_keep_alive_interval` is disabled.
1157
1190
/// Default is currently disabled.
1191
+ #[ cfg( feature = "http2" ) ]
1192
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1158
1193
pub fn http2_keep_alive_timeout ( mut self , timeout : Duration ) -> ClientBuilder {
1159
1194
self . config . http2_keep_alive_timeout = Some ( timeout) ;
1160
1195
self
@@ -1166,6 +1201,8 @@ impl ClientBuilder {
1166
1201
/// If enabled, pings are also sent when no streams are active.
1167
1202
/// Does nothing if `http2_keep_alive_interval` is disabled.
1168
1203
/// Default is `false`.
1204
+ #[ cfg( feature = "http2" ) ]
1205
+ #[ cfg_attr( docsrs, doc( cfg( feature = "http2" ) ) ) ]
1169
1206
pub fn http2_keep_alive_while_idle ( mut self , enabled : bool ) -> ClientBuilder {
1170
1207
self . config . http2_keep_alive_while_idle = enabled;
1171
1208
self
@@ -2008,6 +2045,7 @@ impl Config {
2008
2045
f. field ( "http1_only" , & true ) ;
2009
2046
}
2010
2047
2048
+ #[ cfg( feature = "http2" ) ]
2011
2049
if matches ! ( self . http_version_pref, HttpVersionPref :: Http2 ) {
2012
2050
f. field ( "http2_prior_knowledge" , & true ) ;
2013
2051
}
@@ -2177,7 +2215,10 @@ impl PendingRequest {
2177
2215
self . project ( ) . headers
2178
2216
}
2179
2217
2218
+ #[ cfg( feature = "http2" ) ]
2180
2219
fn retry_error ( mut self : Pin < & mut Self > , err : & ( dyn std:: error:: Error + ' static ) ) -> bool {
2220
+ use log:: trace;
2221
+
2181
2222
if !is_retryable_error ( err) {
2182
2223
return false ;
2183
2224
}
@@ -2234,6 +2275,7 @@ impl PendingRequest {
2234
2275
}
2235
2276
}
2236
2277
2278
+ #[ cfg( feature = "http2" ) ]
2237
2279
fn is_retryable_error ( err : & ( dyn std:: error:: Error + ' static ) ) -> bool {
2238
2280
// pop the legacy::Error
2239
2281
let err = if let Some ( err) = err. source ( ) {
@@ -2311,6 +2353,7 @@ impl Future for PendingRequest {
2311
2353
let res = match self . as_mut ( ) . in_flight ( ) . get_mut ( ) {
2312
2354
ResponseFuture :: Default ( r) => match Pin :: new ( r) . poll ( cx) {
2313
2355
Poll :: Ready ( Err ( e) ) => {
2356
+ #[ cfg( feature = "http2" ) ]
2314
2357
if self . as_mut ( ) . retry_error ( & e) {
2315
2358
continue ;
2316
2359
}
0 commit comments