Skip to content

Commit b9916c4

Browse files
authoredMay 13, 2021
feat(client): allow to config http2 max concurrent reset streams (#2535)
Setting streams to 0 makes h2 work on wasm platforms without a `Instant::now` implementation.
1 parent ccba59f commit b9916c4

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
 

‎src/client/client.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,21 @@ impl Builder {
11511151
self
11521152
}
11531153

1154+
/// Sets the maximum number of HTTP2 concurrent locally reset streams.
1155+
///
1156+
/// See the documentation of [`h2::client::Builder::max_concurrent_reset_streams`] for more
1157+
/// details.
1158+
///
1159+
/// The default value is determined by the `h2` crate.
1160+
///
1161+
/// [`h2::client::Builder::max_concurrent_reset_streams`]: https://docs.rs/h2/client/struct.Builder.html#method.max_concurrent_reset_streams
1162+
#[cfg(feature = "http2")]
1163+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
1164+
pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
1165+
self.conn_builder.http2_max_concurrent_reset_streams(max);
1166+
self
1167+
}
1168+
11541169
/// Set whether to retry requests that get disrupted before ever starting
11551170
/// to write.
11561171
///

‎src/client/conn.rs

+17-1
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,21 @@ 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 determined by the `h2` crate.
711+
///
712+
/// [`h2::client::Builder::max_concurrent_reset_streams`]: https://docs.rs/h2/client/struct.Builder.html#method.max_concurrent_reset_streams
713+
#[cfg(feature = "http2")]
714+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
715+
pub fn http2_max_concurrent_reset_streams(&mut self, max: usize) -> &mut Self {
716+
self.h2_builder.max_concurrent_reset_streams = Some(max);
717+
self
718+
}
719+
704720
/// Constructs a connection with the configured options and IO.
705721
pub fn handshake<T, B>(
706722
&self,

‎src/proto/h2/client.rs

+6-1
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};
@@ -44,6 +44,7 @@ pub(crate) struct Config {
4444
pub(crate) keep_alive_timeout: Duration,
4545
#[cfg(feature = "runtime")]
4646
pub(crate) keep_alive_while_idle: bool,
47+
pub(crate) max_concurrent_reset_streams: Option<usize>,
4748
}
4849

4950
impl Default for Config {
@@ -59,6 +60,7 @@ impl Default for Config {
5960
keep_alive_timeout: Duration::from_secs(20),
6061
#[cfg(feature = "runtime")]
6162
keep_alive_while_idle: false,
63+
max_concurrent_reset_streams: None,
6264
}
6365
}
6466
}
@@ -70,6 +72,9 @@ fn new_builder(config: &Config) -> Builder {
7072
.initial_connection_window_size(config.initial_conn_window_size)
7173
.max_frame_size(config.max_frame_size)
7274
.enable_push(false);
75+
if let Some(max) = config.max_concurrent_reset_streams {
76+
builder.max_concurrent_reset_streams(max);
77+
}
7378
builder
7479
}
7580

0 commit comments

Comments
 (0)
Please sign in to comment.