Skip to content

Commit

Permalink
feat(http2): Add window size config options for Client and Server
Browse files Browse the repository at this point in the history
Add `fn http2_initial_stream_window_size` and `fn
http2_initial_connection_window_size` for client and server.

Closes #1771
  • Loading branch information
kleimkuhler authored and seanmonstar committed Mar 1, 2019
1 parent 2114950 commit 7dcd461
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
31 changes: 30 additions & 1 deletion src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::sync::Arc;
use bytes::Bytes;
use futures::{Async, Future, Poll};
use futures::future::{self, Either, Executor};
use h2;
use tokio_io::{AsyncRead, AsyncWrite};

use body::Payload;
Expand Down Expand Up @@ -77,6 +78,7 @@ pub struct Builder {
h1_read_buf_exact_size: Option<usize>,
h1_max_buf_size: Option<usize>,
http2: bool,
h2_builder: h2::client::Builder,
}

/// A future setting up HTTP over an IO object.
Expand Down Expand Up @@ -431,13 +433,17 @@ impl Builder {
/// Creates a new connection builder.
#[inline]
pub fn new() -> Builder {
let mut h2_builder = h2::client::Builder::default();
h2_builder.enable_push(false);

Builder {
exec: Exec::Default,
h1_writev: true,
h1_read_buf_exact_size: None,
h1_title_case_headers: false,
h1_max_buf_size: None,
http2: false,
h2_builder,
}
}

Expand Down Expand Up @@ -485,6 +491,29 @@ impl Builder {
self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
/// Default is 65,535
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.initial_window_size(sz);
}
self
}

/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.initial_connection_window_size(sz);
}
self
}

/// Constructs a connection with the configured options and IO.
#[inline]
pub fn handshake<T, B>(&self, io: T) -> Handshake<T, B>
Expand Down Expand Up @@ -532,7 +561,7 @@ where
let dispatch = proto::h1::Dispatcher::new(cd, conn);
Either::A(dispatch)
} else {
let h2 = proto::h2::Client::new(io, rx, self.builder.exec.clone());
let h2 = proto::h2::Client::new(io, rx, &self.builder.h2_builder, self.builder.exec.clone());
Either::B(h2)
};

Expand Down
19 changes: 19 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,25 @@ impl Builder {
self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
/// Default is 65,535
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.conn_builder.http2_initial_stream_window_size(sz.into());
self
}

/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.conn_builder.http2_initial_connection_window_size(sz.into());
self
}

/// Sets the maximum idle connection per host allowed in the pool.
///
/// Default is `usize::MAX` (no limit).
Expand Down
7 changes: 2 additions & 5 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ where
T: AsyncRead + AsyncWrite + Send + 'static,
B: Payload,
{
pub(crate) fn new(io: T, rx: ClientRx<B>, exec: Exec) -> Client<T, B> {
let handshake = Builder::new()
// we don't expose PUSH promises yet
.enable_push(false)
.handshake(io);
pub(crate) fn new(io: T, rx: ClientRx<B>, builder: &Builder, exec: Exec) -> Client<T, B> {
let handshake = builder.handshake(io);

Client {
executor: exec,
Expand Down
23 changes: 23 additions & 0 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ impl<E> Http<E> {
self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
/// Default is 65,535
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.initial_window_size(sz);
}
self
}

/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
if let Some(sz) = sz.into() {
self.h2_builder.initial_connection_window_size(sz);
}
self
}

/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
/// connections.
///
Expand Down
19 changes: 19 additions & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ impl<I, E> Builder<I, E> {
self
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
/// stream-level flow control.
///
/// Default is 65,535
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.protocol.http2_initial_stream_window_size(sz.into());
self
}

/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.protocol.http2_initial_connection_window_size(sz.into());
self
}

/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
/// connections.
///
Expand Down

0 comments on commit 7dcd461

Please sign in to comment.