Add methods to {client, server}::Builder to set max concurrent streams (#150)
This PR adds `max_concurrent_streams()` methods to the client and server `Builder`s to set the `max_concurrent_streams` setting. I've added unit tests to ensure the correct SETTINGS frame is sent. Closes #106
This commit is contained in:
@@ -187,6 +187,18 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum number of concurrent streams.
|
||||
///
|
||||
/// Clients can only limit the maximum number of streams that that the
|
||||
/// server can initiate. See [Section 5.1.2] in the HTTP/2 spec for more
|
||||
/// details.
|
||||
///
|
||||
/// [Section 5.1.2]: https://http2.github.io/http2-spec/#rfc.section.5.1.2
|
||||
pub fn max_concurrent_streams(&mut self, max: u32) -> &mut Self {
|
||||
self.settings.set_max_concurrent_streams(Some(max));
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable or disable the server to send push promises.
|
||||
pub fn enable_push(&mut self, enabled: bool) -> &mut Self {
|
||||
self.settings.set_enable_push(enabled);
|
||||
|
||||
@@ -74,7 +74,6 @@ impl Settings {
|
||||
self.max_concurrent_streams
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
pub fn set_max_concurrent_streams(&mut self, max: Option<u32>) {
|
||||
self.max_concurrent_streams = max;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,9 @@ where
|
||||
local_next_stream_id: next_stream_id,
|
||||
local_push_enabled: settings.is_push_enabled(),
|
||||
remote_init_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
|
||||
remote_max_initiated: None,
|
||||
remote_max_initiated: settings
|
||||
.max_concurrent_streams()
|
||||
.map(|max| max as usize),
|
||||
});
|
||||
Connection {
|
||||
state: State::Open,
|
||||
|
||||
@@ -194,6 +194,18 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum number of concurrent streams.
|
||||
///
|
||||
/// Servers can only limit the maximum number of streams that that the
|
||||
/// client can initiate. See [Section 5.1.2] in the HTTP/2 spec for more
|
||||
/// details.
|
||||
///
|
||||
/// [Section 5.1.2]: https://http2.github.io/http2-spec/#rfc.section.5.1.2
|
||||
pub fn max_concurrent_streams(&mut self, max: u32) -> &mut Self {
|
||||
self.settings.set_max_concurrent_streams(Some(max));
|
||||
self
|
||||
}
|
||||
|
||||
/// Bind an H2 server connection.
|
||||
///
|
||||
/// Returns a future which resolves to the connection value once the H2
|
||||
|
||||
Reference in New Issue
Block a user