From fdfa60d9fafb8a6bfb40acc4042ee54a2b9aad32 Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Sat, 20 Jan 2024 02:08:38 +0900 Subject: [PATCH] feat(http2): add `initial_max_send_streams` method to HTTP/2 client builder (#3524) --- src/client/conn/http2.rs | 13 +++++++++++++ src/proto/h2/client.rs | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index 32c3a36b9f..becb518b74 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -305,6 +305,19 @@ where self } + /// Sets the initial maximum of locally initiated (send) streams. + /// + /// This value will be overwritten by the value included in the initial + /// SETTINGS frame received from the peer as part of a [connection preface]. + /// + /// The default value is determined by the `h2` crate, but may change. + /// + /// [connection preface]: https://httpwg.org/specs/rfc9113.html#preface + pub fn initial_max_send_streams(&mut self, initial: impl Into>) -> &mut Self { + self.h2_builder.initial_max_send_streams = initial.into(); + self + } + /// Sets whether to use an adaptive flow control. /// /// Enabling this will override the limits set in diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 7929f7c680..7a716ed9f3 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -57,6 +57,7 @@ pub(crate) struct Config { pub(crate) adaptive_window: bool, pub(crate) initial_conn_window_size: u32, pub(crate) initial_stream_window_size: u32, + pub(crate) initial_max_send_streams: Option, pub(crate) max_frame_size: u32, pub(crate) keep_alive_interval: Option, pub(crate) keep_alive_timeout: Duration, @@ -71,6 +72,7 @@ impl Default for Config { adaptive_window: false, initial_conn_window_size: DEFAULT_CONN_WINDOW, initial_stream_window_size: DEFAULT_STREAM_WINDOW, + initial_max_send_streams: None, max_frame_size: DEFAULT_MAX_FRAME_SIZE, keep_alive_interval: None, keep_alive_timeout: Duration::from_secs(20), @@ -89,6 +91,9 @@ fn new_builder(config: &Config) -> Builder { .max_frame_size(config.max_frame_size) .max_send_buffer_size(config.max_send_buffer_size) .enable_push(false); + if let Some(initial_max_send_streams) = config.initial_max_send_streams { + builder.initial_max_send_streams(initial_max_send_streams); + } if let Some(max) = config.max_concurrent_reset_streams { builder.max_concurrent_reset_streams(max); }