Skip to content

Commit 4e6d835

Browse files
committed
Add a setter for header_table_size
1 parent 88b0789 commit 4e6d835

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

src/client.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,39 @@ impl Builder {
10221022
self
10231023
}
10241024

1025+
/// Sets the header table size.
1026+
///
1027+
/// This setting informs the peer of the maximum size of the header compression
1028+
/// table used to encode header blocks, in octets. The encoder may select any value
1029+
/// equal to or less than the header table size specified by the sender.
1030+
///
1031+
/// The default value is 4,096.
1032+
///
1033+
/// # Examples
1034+
///
1035+
/// ```
1036+
/// # use tokio::io::{AsyncRead, AsyncWrite};
1037+
/// # use h2::client::*;
1038+
/// # use bytes::Bytes;
1039+
/// #
1040+
/// # async fn doc<T: AsyncRead + AsyncWrite + Unpin>(my_io: T)
1041+
/// # -> Result<((SendRequest<Bytes>, Connection<T, Bytes>)), h2::Error>
1042+
/// # {
1043+
/// // `client_fut` is a future representing the completion of the HTTP/2
1044+
/// // handshake.
1045+
/// let client_fut = Builder::new()
1046+
/// .header_table_size(1_000_000)
1047+
/// .handshake(my_io);
1048+
/// # client_fut.await
1049+
/// # }
1050+
/// #
1051+
/// # pub fn main() {}
1052+
/// ```
1053+
pub fn header_table_size(&mut self, size: u32) -> &mut Self {
1054+
self.settings.set_header_table_size(Some(size));
1055+
self
1056+
}
1057+
10251058
/// Sets the first stream ID to something other than 1.
10261059
#[cfg(feature = "unstable")]
10271060
pub fn initial_stream_id(&mut self, stream_id: u32) -> &mut Self {

src/codec/framed_read.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ impl<T> FramedRead<T> {
8888
pub fn set_max_header_list_size(&mut self, val: usize) {
8989
self.max_header_list_size = val;
9090
}
91+
92+
/// Update the header table size setting.
93+
#[inline]
94+
pub fn set_header_table_size(&mut self, val: usize) {
95+
self.hpack.queue_size_update(val);
96+
}
9197
}
9298

9399
/// Decodes a frame.

src/codec/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ impl<T, B> Codec<T, B> {
9595
self.framed_write().set_header_table_size(val)
9696
}
9797

98+
/// Set the decoder header table size size.
99+
pub fn set_recv_header_table_size(&mut self, val: usize) {
100+
self.inner.set_header_table_size(val)
101+
}
102+
98103
/// Set the max header list size that can be received.
99104
pub fn set_max_recv_header_list_size(&mut self, val: usize) {
100105
self.inner.set_max_header_list_size(val);

src/frame/settings.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ impl Settings {
120120
pub fn header_table_size(&self) -> Option<u32> {
121121
self.header_table_size
122122
}
123-
124-
/*
123+
125124
pub fn set_header_table_size(&mut self, size: Option<u32>) {
126125
self.header_table_size = size;
127126
}
128-
*/
129127

130128
pub fn load(head: Head, payload: &[u8]) -> Result<Settings, Error> {
131129
use self::Setting::*;

src/proto/settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ impl Settings {
6060
codec.set_max_recv_header_list_size(max as usize);
6161
}
6262

63+
if let Some(val) = local.header_table_size() {
64+
codec.set_recv_header_table_size(val as usize);
65+
}
66+
6367
streams.apply_local_settings(local)?;
6468
self.local = Local::Synced;
6569
Ok(())

0 commit comments

Comments
 (0)