Skip to content

Commit a6f7571

Browse files
authoredApr 13, 2023
feat(http2): add max_pending_accept_reset_streams configuration option (#3201)
This allows users to set the configuration option from hyperium/h2#668.
1 parent a9d4e83 commit a6f7571

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed
 

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ http = "0.2"
2828
http-body = "0.4"
2929
httpdate = "1.0"
3030
httparse = "1.8"
31-
h2 = { version = "0.3.9", optional = true }
31+
h2 = { version = "0.3.17", optional = true }
3232
itoa = "1"
3333
tracing = { version = "0.1", default-features = false, features = ["std"] }
3434
pin-project-lite = "0.2.4"

‎src/body/body.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
3030
/// A good default [`HttpBody`](crate::body::HttpBody) to use in many
3131
/// applications.
3232
///
33-
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes)
34-
/// or [`body::aggregate`](crate::body::aggregate).
33+
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes())
34+
/// or [`body::aggregate`](crate::body::aggregate()).
3535
#[must_use = "streams do nothing unless polled"]
3636
pub struct Body {
3737
kind: Kind,

‎src/proto/h2/server.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(crate) struct Config {
4646
pub(crate) max_frame_size: u32,
4747
pub(crate) enable_connect_protocol: bool,
4848
pub(crate) max_concurrent_streams: Option<u32>,
49+
pub(crate) max_pending_accept_reset_streams: Option<usize>,
4950
#[cfg(feature = "runtime")]
5051
pub(crate) keep_alive_interval: Option<Duration>,
5152
#[cfg(feature = "runtime")]
@@ -63,6 +64,7 @@ impl Default for Config {
6364
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
6465
enable_connect_protocol: false,
6566
max_concurrent_streams: None,
67+
max_pending_accept_reset_streams: None,
6668
#[cfg(feature = "runtime")]
6769
keep_alive_interval: None,
6870
#[cfg(feature = "runtime")]
@@ -125,6 +127,9 @@ where
125127
if let Some(max) = config.max_concurrent_streams {
126128
builder.max_concurrent_streams(max);
127129
}
130+
if let Some(max) = config.max_pending_accept_reset_streams {
131+
builder.max_pending_accept_reset_streams(max);
132+
}
128133
if config.enable_connect_protocol {
129134
builder.enable_connect_protocol();
130135
}
@@ -503,7 +508,6 @@ where
503508
}
504509
}
505510

506-
507511
if !body.is_end_stream() {
508512
// automatically set Content-Length from body...
509513
if let Some(len) = body.size_hint().exact() {

‎src/server/conn.rs

+17
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ impl<E> Http<E> {
394394
self
395395
}
396396

397+
/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
398+
///
399+
/// This will default to the default value set by the [`h2` crate](https://crates.io/crates/h2).
400+
/// As of v0.3.17, it is 20.
401+
///
402+
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
403+
#[cfg(feature = "http2")]
404+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
405+
pub fn http2_max_pending_accept_reset_streams(
406+
&mut self,
407+
max: impl Into<Option<usize>>,
408+
) -> &mut Self {
409+
self.h2_builder.max_pending_accept_reset_streams = max.into();
410+
411+
self
412+
}
413+
397414
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
398415
/// stream-level flow control.
399416
///

‎src/server/server.rs

+12
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ impl<I, E> Builder<I, E> {
373373
self
374374
}
375375

376+
/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
377+
///
378+
/// This will default to whatever the default in h2 is. As of v0.3.17, it is 20.
379+
///
380+
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
381+
#[cfg(feature = "http2")]
382+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
383+
pub fn http2_max_pending_accept_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
384+
self.protocol.http2_max_pending_accept_reset_streams(max);
385+
self
386+
}
387+
376388
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
377389
/// stream-level flow control.
378390
///

0 commit comments

Comments
 (0)
Please sign in to comment.