Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) struct Config {
pub(crate) keep_alive_interval: Option<Duration>,
pub(crate) keep_alive_timeout: Duration,
pub(crate) max_send_buffer_size: usize,
pub(crate) header_table_size: Option<u32>,
pub(crate) max_header_list_size: u32,
pub(crate) date_header: bool,
}
Expand All @@ -68,6 +69,7 @@ impl Default for Config {
max_concurrent_streams: Some(200),
max_pending_accept_reset_streams: None,
max_local_error_reset_streams: Some(DEFAULT_MAX_LOCAL_ERROR_RESET_STREAMS),
header_table_size: None,
keep_alive_interval: None,
keep_alive_timeout: Duration::from_secs(20),
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
Expand Down Expand Up @@ -142,6 +144,9 @@ where
if let Some(max) = config.max_pending_accept_reset_streams {
builder.max_pending_accept_reset_streams(max);
}
if let Some(size) = config.header_table_size {
builder.header_table_size(size);
}
if config.enable_connect_protocol {
builder.enable_connect_protocol();
}
Expand Down
12 changes: 12 additions & 0 deletions src/server/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ impl<E> Builder<E> {
self
}

/// Sets the header table size.
///
/// This setting informs the peer of the maximum size of the header compression
/// table used to encode header blocks, in octets. The encoder may select any value
/// equal to or less than the header table size specified by the sender.
///
/// The default value of crate `h2` is 4,096.
pub fn header_table_size(&mut self, size: impl Into<Option<u32>>) -> &mut Self {
self.h2_builder.header_table_size = size.into();
self
}

/// Sets the max size of received header frames.
///
/// Default is currently 16KB, but can change.
Expand Down
30 changes: 30 additions & 0 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,36 @@ async fn http2_keep_alive_count_server_pings() {
.expect("timed out waiting for pings");
}

#[tokio::test]
async fn http2_header_table_size() {
let (listener, addr) = setup_tcp_listener();

tokio::spawn(async move {
let (socket, _) = listener.accept().await.expect("accept");
let socket = TokioIo::new(socket);

http2::Builder::new(TokioExecutor)
.header_table_size(8192)
.serve_connection(socket, HelloWorld)
.await
.expect("serve_connection");
});

let tcp = TokioIo::new(connect_async(addr).await);
let (mut client, conn) = hyper::client::conn::http2::Builder::new(TokioExecutor)
.handshake(tcp)
.await
.expect("http handshake");

tokio::spawn(async move {
conn.await.expect("client conn");
});

let req = http::Request::new(Empty::<Bytes>::new());
let res = client.send_request(req).await.expect("client.send_request");
assert_eq!(res.status(), StatusCode::OK);
}

#[test]
fn http1_trailer_send_fields() {
let body = futures_util::stream::once(async move { Ok("hello".into()) });
Expand Down
Loading