Skip to content

Commit 7d0d0b2

Browse files
committed
feat(http2): add initial_max_send_streams method to HTTP/2 client builder
1 parent 8241f91 commit 7d0d0b2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/client/conn/http2.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,23 @@ where
305305
self
306306
}
307307

308+
/// Sets the initial maximum of locally initiated (send) streams.
309+
///
310+
/// This value will be overwritten by the value included in the initial
311+
/// SETTINGS frame received from the peer as part of a [connection preface].
312+
///
313+
/// Passing `None` will do nothing.
314+
///
315+
/// If not set, hyper will use a default.
316+
///
317+
/// [connection preface]: https://httpwg.org/specs/rfc9113.html#preface
318+
pub fn initial_max_send_streams(&mut self, initial: impl Into<Option<usize>>) -> &mut Self {
319+
if let Some(initial) = initial.into() {
320+
self.h2_builder.initial_max_send_streams = initial;
321+
}
322+
self
323+
}
324+
308325
/// Sets whether to use an adaptive flow control.
309326
///
310327
/// Enabling this will override the limits set in

src/proto/h2/client.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,21 @@ const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
5252
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
5353
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 1024; // 1mb
5454

55+
// The maximum number of concurrent streams that the client is allowed to open
56+
// before it receives the initial SETTINGS frame from the server.
57+
// This default value is derived from what the HTTP/2 spec recommends as the
58+
// minimum value that endpoints advertise to their peers. It means that using
59+
// this value will minimize the chance of the failure where the local endpoint
60+
// attempts to open too many streams and gets rejected by the remote peer with
61+
// the `REFUSED_STREAM` error.
62+
const DEFAULT_INITIAL_MAX_SEND_STREAMS: usize = 100;
63+
5564
#[derive(Clone, Debug)]
5665
pub(crate) struct Config {
5766
pub(crate) adaptive_window: bool,
5867
pub(crate) initial_conn_window_size: u32,
5968
pub(crate) initial_stream_window_size: u32,
69+
pub(crate) initial_max_send_streams: usize,
6070
pub(crate) max_frame_size: u32,
6171
pub(crate) keep_alive_interval: Option<Duration>,
6272
pub(crate) keep_alive_timeout: Duration,
@@ -71,6 +81,7 @@ impl Default for Config {
7181
adaptive_window: false,
7282
initial_conn_window_size: DEFAULT_CONN_WINDOW,
7383
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
84+
initial_max_send_streams: DEFAULT_INITIAL_MAX_SEND_STREAMS,
7485
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
7586
keep_alive_interval: None,
7687
keep_alive_timeout: Duration::from_secs(20),
@@ -84,6 +95,7 @@ impl Default for Config {
8495
fn new_builder(config: &Config) -> Builder {
8596
let mut builder = Builder::default();
8697
builder
98+
.initial_max_send_streams(config.initial_max_send_streams)
8799
.initial_window_size(config.initial_stream_window_size)
88100
.initial_connection_window_size(config.initial_conn_window_size)
89101
.max_frame_size(config.max_frame_size)

0 commit comments

Comments
 (0)