Skip to content

Commit

Permalink
feat(http2): add max_pending_accept_reset_streams configuration opt…
Browse files Browse the repository at this point in the history
…ion (#3201)

This allows users to set the configuration option from hyperium/h2#668.
  • Loading branch information
Noah-Kennedy authored Apr 13, 2023
1 parent a9d4e83 commit a6f7571
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ http = "0.2"
http-body = "0.4"
httpdate = "1.0"
httparse = "1.8"
h2 = { version = "0.3.9", optional = true }
h2 = { version = "0.3.17", optional = true }
itoa = "1"
tracing = { version = "0.1", default-features = false, features = ["std"] }
pin-project-lite = "0.2.4"
Expand Down
4 changes: 2 additions & 2 deletions src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
/// A good default [`HttpBody`](crate::body::HttpBody) to use in many
/// applications.
///
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes)
/// or [`body::aggregate`](crate::body::aggregate).
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes())
/// or [`body::aggregate`](crate::body::aggregate()).
#[must_use = "streams do nothing unless polled"]
pub struct Body {
kind: Kind,
Expand Down
6 changes: 5 additions & 1 deletion src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) struct Config {
pub(crate) max_frame_size: u32,
pub(crate) enable_connect_protocol: bool,
pub(crate) max_concurrent_streams: Option<u32>,
pub(crate) max_pending_accept_reset_streams: Option<usize>,
#[cfg(feature = "runtime")]
pub(crate) keep_alive_interval: Option<Duration>,
#[cfg(feature = "runtime")]
Expand All @@ -63,6 +64,7 @@ impl Default for Config {
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
enable_connect_protocol: false,
max_concurrent_streams: None,
max_pending_accept_reset_streams: None,
#[cfg(feature = "runtime")]
keep_alive_interval: None,
#[cfg(feature = "runtime")]
Expand Down Expand Up @@ -125,6 +127,9 @@ where
if let Some(max) = config.max_concurrent_streams {
builder.max_concurrent_streams(max);
}
if let Some(max) = config.max_pending_accept_reset_streams {
builder.max_pending_accept_reset_streams(max);
}
if config.enable_connect_protocol {
builder.enable_connect_protocol();
}
Expand Down Expand Up @@ -503,7 +508,6 @@ where
}
}


if !body.is_end_stream() {
// automatically set Content-Length from body...
if let Some(len) = body.size_hint().exact() {
Expand Down
17 changes: 17 additions & 0 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ impl<E> Http<E> {
self
}

/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
///
/// This will default to the default value set by the [`h2` crate](https://crates.io/crates/h2).
/// As of v0.3.17, it is 20.
///
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_max_pending_accept_reset_streams(
&mut self,
max: impl Into<Option<usize>>,
) -> &mut Self {
self.h2_builder.max_pending_accept_reset_streams = max.into();

self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
Expand Down
12 changes: 12 additions & 0 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ impl<I, E> Builder<I, E> {
self
}

/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
///
/// This will default to whatever the default in h2 is. As of v0.3.17, it is 20.
///
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_max_pending_accept_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
self.protocol.http2_max_pending_accept_reset_streams(max);
self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
Expand Down

0 comments on commit a6f7571

Please sign in to comment.