From aba17618b8438b9c4e843012eca7878da6c27c71 Mon Sep 17 00:00:00 2001 From: boxdot Date: Mon, 3 May 2021 16:29:11 +0200 Subject: [PATCH] feat(client): allow to config http2 max concurrent reset streams Setting streams to 0 makes h2 work on wasm platforms without a `Instant::now` implementation. The default value if derived from the default value in the h2 crate. --- src/client/client.rs | 15 +++++++++++++++ src/client/conn.rs | 18 +++++++++++++++++- src/proto/h2/client.rs | 7 ++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/client/client.rs b/src/client/client.rs index 5545eab997..90d94e12ed 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -1151,6 +1151,21 @@ impl Builder { self } + /// Sets the maximum number of HTTP2 concurrent locally reset streams. + /// + /// See the documentation of [`h2::client::Builder::max_concurrent_reset_streams`] for more + /// details. + /// + /// The default value is determined by the `h2` crate. + /// + /// [`h2::client::Builder::max_concurrent_reset_streams`]: https://docs.rs/h2/client/struct.Builder.html#method.max_concurrent_reset_streams + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self { + self.conn_builder.http2_max_concurrent_reset_streams(max); + self + } + /// Set whether to retry requests that get disrupted before ever starting /// to write. /// diff --git a/src/client/conn.rs b/src/client/conn.rs index ef98fd30ce..70c1dad248 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -530,7 +530,8 @@ impl Builder { &mut self, enabled: bool, ) -> &mut Builder { - self.h1_parser_config.allow_spaces_after_header_name_in_responses(enabled); + self.h1_parser_config + .allow_spaces_after_header_name_in_responses(enabled); self } @@ -701,6 +702,21 @@ impl Builder { self } + /// Sets the maximum number of HTTP2 concurrent locally reset streams. + /// + /// See the documentation of [`h2::client::Builder::max_concurrent_reset_streams`] for more + /// details. + /// + /// The default value is determined by the `h2` crate. + /// + /// [`h2::client::Builder::max_concurrent_reset_streams`]: https://docs.rs/h2/client/struct.Builder.html#method.max_concurrent_reset_streams + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self { + self.h2_builder.max_concurrent_reset_streams = Some(max); + self + } + /// Constructs a connection with the configured options and IO. pub fn handshake( &self, diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 4f583f2bfa..6d310e94c9 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -10,7 +10,7 @@ use tokio::io::{AsyncRead, AsyncWrite}; use super::{decode_content_length, ping, PipeToSendStream, SendBuf}; use crate::body::HttpBody; -use crate::common::{task, exec::Exec, Future, Never, Pin, Poll}; +use crate::common::{exec::Exec, task, Future, Never, Pin, Poll}; use crate::headers; use crate::proto::Dispatched; use crate::{Body, Request, Response}; @@ -44,6 +44,7 @@ pub(crate) struct Config { pub(crate) keep_alive_timeout: Duration, #[cfg(feature = "runtime")] pub(crate) keep_alive_while_idle: bool, + pub(crate) max_concurrent_reset_streams: Option, } impl Default for Config { @@ -59,6 +60,7 @@ impl Default for Config { keep_alive_timeout: Duration::from_secs(20), #[cfg(feature = "runtime")] keep_alive_while_idle: false, + max_concurrent_reset_streams: None, } } } @@ -70,6 +72,9 @@ fn new_builder(config: &Config) -> Builder { .initial_connection_window_size(config.initial_conn_window_size) .max_frame_size(config.max_frame_size) .enable_push(false); + if let Some(max) = config.max_concurrent_reset_streams { + builder.max_concurrent_reset_streams(max); + } builder }