Skip to content

Commit

Permalink
feat(client): allow to config h2 max concurrent reset streams
Browse files Browse the repository at this point in the history
Setting streams to 0 makes h2 work on wasm platforms without a
`Instant::now` implementation.
  • Loading branch information
boxdot committed May 5, 2021
1 parent d1d2f32 commit 7ca0433
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/client/client.rs
Expand Up @@ -1148,6 +1148,19 @@ 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 10.
#[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.
///
Expand Down
16 changes: 15 additions & 1 deletion src/client/conn.rs
Expand Up @@ -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
}

Expand Down Expand Up @@ -701,6 +702,19 @@ 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 10.
#[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 = max;
self
}

/// Constructs a connection with the configured options and IO.
pub fn handshake<T, B>(
&self,
Expand Down
9 changes: 8 additions & 1 deletion src/proto/h2/client.rs
Expand Up @@ -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};
Expand All @@ -32,6 +32,10 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024 * 5; // 5mb
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb

// Same as the default value in `h2`:
// https://docs.rs/h2/0.3.3/h2/client/struct.Builder.html#method.max_concurrent_reset_streams
const DEFAULT_MAX_CONCURRENT_RESET_STREAMS: usize = 10;

#[derive(Clone, Debug)]
pub(crate) struct Config {
pub(crate) adaptive_window: bool,
Expand All @@ -44,6 +48,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: usize,
}

impl Default for Config {
Expand All @@ -59,6 +64,7 @@ impl Default for Config {
keep_alive_timeout: Duration::from_secs(20),
#[cfg(feature = "runtime")]
keep_alive_while_idle: false,
max_concurrent_reset_streams: DEFAULT_MAX_CONCURRENT_RESET_STREAMS,
}
}
}
Expand All @@ -69,6 +75,7 @@ fn new_builder(config: &Config) -> Builder {
.initial_window_size(config.initial_stream_window_size)
.initial_connection_window_size(config.initial_conn_window_size)
.max_frame_size(config.max_frame_size)
.max_concurrent_reset_streams(config.max_concurrent_reset_streams)
.enable_push(false);
builder
}
Expand Down

0 comments on commit 7ca0433

Please sign in to comment.