Skip to content

Commit 7dcd461

Browse files
kleimkuhlerseanmonstar
authored andcommitted
feat(http2): Add window size config options for Client and Server
Add `fn http2_initial_stream_window_size` and `fn http2_initial_connection_window_size` for client and server. Closes #1771
1 parent 2114950 commit 7dcd461

File tree

5 files changed

+93
-6
lines changed

5 files changed

+93
-6
lines changed

src/client/conn.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::sync::Arc;
1515
use bytes::Bytes;
1616
use futures::{Async, Future, Poll};
1717
use futures::future::{self, Either, Executor};
18+
use h2;
1819
use tokio_io::{AsyncRead, AsyncWrite};
1920

2021
use body::Payload;
@@ -77,6 +78,7 @@ pub struct Builder {
7778
h1_read_buf_exact_size: Option<usize>,
7879
h1_max_buf_size: Option<usize>,
7980
http2: bool,
81+
h2_builder: h2::client::Builder,
8082
}
8183

8284
/// A future setting up HTTP over an IO object.
@@ -431,13 +433,17 @@ impl Builder {
431433
/// Creates a new connection builder.
432434
#[inline]
433435
pub fn new() -> Builder {
436+
let mut h2_builder = h2::client::Builder::default();
437+
h2_builder.enable_push(false);
438+
434439
Builder {
435440
exec: Exec::Default,
436441
h1_writev: true,
437442
h1_read_buf_exact_size: None,
438443
h1_title_case_headers: false,
439444
h1_max_buf_size: None,
440445
http2: false,
446+
h2_builder,
441447
}
442448
}
443449

@@ -485,6 +491,29 @@ impl Builder {
485491
self
486492
}
487493

494+
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
495+
/// stream-level flow control.
496+
///
497+
/// Default is 65,535
498+
///
499+
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
500+
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
501+
if let Some(sz) = sz.into() {
502+
self.h2_builder.initial_window_size(sz);
503+
}
504+
self
505+
}
506+
507+
/// Sets the max connection-level flow control for HTTP2
508+
///
509+
/// Default is 65,535
510+
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
511+
if let Some(sz) = sz.into() {
512+
self.h2_builder.initial_connection_window_size(sz);
513+
}
514+
self
515+
}
516+
488517
/// Constructs a connection with the configured options and IO.
489518
#[inline]
490519
pub fn handshake<T, B>(&self, io: T) -> Handshake<T, B>
@@ -532,7 +561,7 @@ where
532561
let dispatch = proto::h1::Dispatcher::new(cd, conn);
533562
Either::A(dispatch)
534563
} else {
535-
let h2 = proto::h2::Client::new(io, rx, self.builder.exec.clone());
564+
let h2 = proto::h2::Client::new(io, rx, &self.builder.h2_builder, self.builder.exec.clone());
536565
Either::B(h2)
537566
};
538567

src/client/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,25 @@ impl Builder {
971971
self
972972
}
973973

974+
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
975+
/// stream-level flow control.
976+
///
977+
/// Default is 65,535
978+
///
979+
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
980+
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
981+
self.conn_builder.http2_initial_stream_window_size(sz.into());
982+
self
983+
}
984+
985+
/// Sets the max connection-level flow control for HTTP2
986+
///
987+
/// Default is 65,535
988+
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
989+
self.conn_builder.http2_initial_connection_window_size(sz.into());
990+
self
991+
}
992+
974993
/// Sets the maximum idle connection per host allowed in the pool.
975994
///
976995
/// Default is `usize::MAX` (no limit).

src/proto/h2/client.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ where
3737
T: AsyncRead + AsyncWrite + Send + 'static,
3838
B: Payload,
3939
{
40-
pub(crate) fn new(io: T, rx: ClientRx<B>, exec: Exec) -> Client<T, B> {
41-
let handshake = Builder::new()
42-
// we don't expose PUSH promises yet
43-
.enable_push(false)
44-
.handshake(io);
40+
pub(crate) fn new(io: T, rx: ClientRx<B>, builder: &Builder, exec: Exec) -> Client<T, B> {
41+
let handshake = builder.handshake(io);
4542

4643
Client {
4744
executor: exec,

src/server/conn.rs

+23
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ impl<E> Http<E> {
239239
self
240240
}
241241

242+
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
243+
/// stream-level flow control.
244+
///
245+
/// Default is 65,535
246+
///
247+
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
248+
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
249+
if let Some(sz) = sz.into() {
250+
self.h2_builder.initial_window_size(sz);
251+
}
252+
self
253+
}
254+
255+
/// Sets the max connection-level flow control for HTTP2
256+
///
257+
/// Default is 65,535
258+
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
259+
if let Some(sz) = sz.into() {
260+
self.h2_builder.initial_connection_window_size(sz);
261+
}
262+
self
263+
}
264+
242265
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
243266
/// connections.
244267
///

src/server/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ impl<I, E> Builder<I, E> {
302302
self
303303
}
304304

305+
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
306+
/// stream-level flow control.
307+
///
308+
/// Default is 65,535
309+
///
310+
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
311+
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
312+
self.protocol.http2_initial_stream_window_size(sz.into());
313+
self
314+
}
315+
316+
/// Sets the max connection-level flow control for HTTP2
317+
///
318+
/// Default is 65,535
319+
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
320+
self.protocol.http2_initial_connection_window_size(sz.into());
321+
self
322+
}
323+
305324
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
306325
/// connections.
307326
///

0 commit comments

Comments
 (0)