From 7a0145e1da0f020e514311bfa8c2734f92a00d9f Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 09:41:51 -0500 Subject: [PATCH 1/6] h2: add max_pending_accept_reset_streams configuration option This allows users to set the configuration option from /~https://github.com/hyperium/h2/pull/668. --- Cargo.toml | 10 +++++----- src/proto/h2/server.rs | 8 ++++++-- src/server/conn.rs | 11 +++++++++++ src/server/server.rs | 10 ++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5818b08225..7856690ca2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,10 @@ categories = ["network-programming", "web-programming::http-client", "web-progra edition = "2018" include = [ - "Cargo.toml", - "LICENSE", - "src/**/*", - #"build.rs", + "Cargo.toml", + "LICENSE", + "src/**/*", + #"build.rs", ] [dependencies] @@ -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" diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index d24e6bac5f..27df2ca984 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -35,7 +35,7 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb -// 16 MB "sane default" taken from golang http2 + // 16 MB "sane default" taken from golang http2 const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20; #[derive(Clone, Debug)] @@ -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, + pub(crate) max_pending_accept_reset_streams: Option, #[cfg(feature = "runtime")] pub(crate) keep_alive_interval: Option, #[cfg(feature = "runtime")] @@ -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")] @@ -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(); } @@ -503,7 +508,6 @@ where } } - if !body.is_end_stream() { // automatically set Content-Length from body... if let Some(len) = body.size_hint().exact() { diff --git a/src/server/conn.rs b/src/server/conn.rs index f820e083d0..ef522524fb 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -394,6 +394,17 @@ impl Http { self } + /// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent. + /// + /// See for more information. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_pending_accept_reset_streams(&mut self, max: usize) -> &mut Self { + self.h2_builder.max_pending_accept_reset_streams = Some(max); + + self + } + /// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2 /// stream-level flow control. /// diff --git a/src/server/server.rs b/src/server/server.rs index e4273674fc..44bfbcd57b 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -373,6 +373,16 @@ impl Builder { self } + /// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent. + /// + /// See for more information. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_pending_accept_reset_streams(mut self, max: 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. /// From 2e537ab8cac161781cb3bb11f174e8c69474aa32 Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 11:36:54 -0500 Subject: [PATCH 2/6] Update Cargo.toml Co-authored-by: Eliza Weisman --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7856690ca2..754177c718 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,10 @@ categories = ["network-programming", "web-programming::http-client", "web-progra edition = "2018" include = [ - "Cargo.toml", - "LICENSE", - "src/**/*", - #"build.rs", + "Cargo.toml", + "LICENSE", + "src/**/*", + #"build.rs", ] [dependencies] From 87ccc28c44be6a17e21231a32b06e1e0c88605af Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 11:37:55 -0500 Subject: [PATCH 3/6] Update src/proto/h2/server.rs Co-authored-by: Eliza Weisman --- src/proto/h2/server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto/h2/server.rs b/src/proto/h2/server.rs index 27df2ca984..4127387e71 100644 --- a/src/proto/h2/server.rs +++ b/src/proto/h2/server.rs @@ -35,7 +35,7 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb - // 16 MB "sane default" taken from golang http2 +// 16 MB "sane default" taken from golang http2 const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20; #[derive(Clone, Debug)] From fc76aaf3e88a70efb07ad7407cdf9fd5c657eedf Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 12:40:44 -0500 Subject: [PATCH 4/6] impl into option --- src/server/conn.rs | 9 +++++++-- src/server/server.rs | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/server/conn.rs b/src/server/conn.rs index ef522524fb..8bc99833f2 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -396,11 +396,16 @@ impl Http { /// 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 for more information. #[cfg(feature = "http2")] #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] - pub fn http2_max_pending_accept_reset_streams(&mut self, max: usize) -> &mut Self { - self.h2_builder.max_pending_accept_reset_streams = Some(max); + pub fn http2_max_pending_accept_reset_streams( + &mut self, + max: impl Into>, + ) -> &mut Self { + self.h2_builder.max_pending_accept_reset_streams = max.into(); self } diff --git a/src/server/server.rs b/src/server/server.rs index 44bfbcd57b..c90eac3e53 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -375,10 +375,12 @@ impl Builder { /// 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 for more information. #[cfg(feature = "http2")] #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] - pub fn http2_max_pending_accept_reset_streams(mut self, max: usize) -> Self { + pub fn http2_max_pending_accept_reset_streams(mut self, max: impl Into>) -> Self { self.protocol.http2_max_pending_accept_reset_streams(max); self } From ea8c7a1669ceaeedcbed4b1d15e7d45a574a77a3 Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 13:17:48 -0500 Subject: [PATCH 5/6] fix grumpy ci --- src/body/body.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/body/body.rs b/src/body/body.rs index 9dc1a034f9..699398b86f 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -30,8 +30,8 @@ type TrailersSender = oneshot::Sender; /// 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, From e8296d1c5bded88a508f1ca1f35791c30803182d Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Thu, 13 Apr 2023 13:22:51 -0500 Subject: [PATCH 6/6] Update src/server/conn.rs Co-authored-by: Eliza Weisman --- src/server/conn.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/conn.rs b/src/server/conn.rs index 8bc99833f2..dfe2172457 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -396,7 +396,8 @@ impl Http { /// 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. + /// 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 for more information. #[cfg(feature = "http2")]