Skip to content

Commit 7ca0433

Browse files
committed
feat(client): allow to config h2 max concurrent reset streams
Setting streams to 0 makes h2 work on wasm platforms without a `Instant::now` implementation.
1 parent d1d2f32 commit 7ca0433

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/client/client.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,19 @@ impl Builder {
11481148
self
11491149
}
11501150

1151+
/// Sets the maximum number of HTTP2 concurrent locally reset streams.
1152+
///
1153+
/// See the documentation of [`h2::client::Builder::max_concurrent_reset_streams`] for more
1154+
/// details.
1155+
///
1156+
/// The default value is 10.
1157+
#[cfg(feature = "http2")]
1158+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
1159+
pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
1160+
self.conn_builder.http2_max_concurrent_reset_streams(max);
1161+
self
1162+
}
1163+
11511164
/// Set whether to retry requests that get disrupted before ever starting
11521165
/// to write.
11531166
///

src/client/conn.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ impl Builder {
530530
&mut self,
531531
enabled: bool,
532532
) -> &mut Builder {
533-
self.h1_parser_config.allow_spaces_after_header_name_in_responses(enabled);
533+
self.h1_parser_config
534+
.allow_spaces_after_header_name_in_responses(enabled);
534535
self
535536
}
536537

@@ -701,6 +702,19 @@ impl Builder {
701702
self
702703
}
703704

705+
/// Sets the maximum number of HTTP2 concurrent locally reset streams.
706+
///
707+
/// See the documentation of [`h2::client::Builder::max_concurrent_reset_streams`] for more
708+
/// details.
709+
///
710+
/// The default value is 10.
711+
#[cfg(feature = "http2")]
712+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
713+
pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
714+
self.h2_builder.max_concurrent_reset_streams = max;
715+
self
716+
}
717+
704718
/// Constructs a connection with the configured options and IO.
705719
pub fn handshake<T, B>(
706720
&self,

src/proto/h2/client.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
1010

1111
use super::{decode_content_length, ping, PipeToSendStream, SendBuf};
1212
use crate::body::HttpBody;
13-
use crate::common::{task, exec::Exec, Future, Never, Pin, Poll};
13+
use crate::common::{exec::Exec, task, Future, Never, Pin, Poll};
1414
use crate::headers;
1515
use crate::proto::Dispatched;
1616
use crate::{Body, Request, Response};
@@ -32,6 +32,10 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024 * 5; // 5mb
3232
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
3333
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
3434

35+
// Same as the default value in `h2`:
36+
// https://docs.rs/h2/0.3.3/h2/client/struct.Builder.html#method.max_concurrent_reset_streams
37+
const DEFAULT_MAX_CONCURRENT_RESET_STREAMS: usize = 10;
38+
3539
#[derive(Clone, Debug)]
3640
pub(crate) struct Config {
3741
pub(crate) adaptive_window: bool,
@@ -44,6 +48,7 @@ pub(crate) struct Config {
4448
pub(crate) keep_alive_timeout: Duration,
4549
#[cfg(feature = "runtime")]
4650
pub(crate) keep_alive_while_idle: bool,
51+
pub(crate) max_concurrent_reset_streams: usize,
4752
}
4853

4954
impl Default for Config {
@@ -59,6 +64,7 @@ impl Default for Config {
5964
keep_alive_timeout: Duration::from_secs(20),
6065
#[cfg(feature = "runtime")]
6166
keep_alive_while_idle: false,
67+
max_concurrent_reset_streams: DEFAULT_MAX_CONCURRENT_RESET_STREAMS,
6268
}
6369
}
6470
}
@@ -69,6 +75,7 @@ fn new_builder(config: &Config) -> Builder {
6975
.initial_window_size(config.initial_stream_window_size)
7076
.initial_connection_window_size(config.initial_conn_window_size)
7177
.max_frame_size(config.max_frame_size)
78+
.max_concurrent_reset_streams(config.max_concurrent_reset_streams)
7279
.enable_push(false);
7380
builder
7481
}

0 commit comments

Comments
 (0)