Skip to content

Commit

Permalink
feat: adapt configurable max_headers
Browse files Browse the repository at this point in the history
Adapts configurable `max_headers` by hyperium/hyper#3523.
  • Loading branch information
wfly1998 committed Mar 11, 2024
1 parent a24c162 commit b040494
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,28 @@ impl Builder {
self
}

/// Set the maximum number of headers.
///
/// When a response is received, the parser will reserve a buffer to store headers for optimal
/// performance.
///
/// If client receives more headers than the buffer size, the error "message header too large"
/// is returned.
///
/// The headers is allocated on the stack by default, which has higher performance. After
/// setting this value, headers will be allocated in heap memory, that is, heap memory
/// allocation will occur for each response, and there will be a performance drop of about 5%.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is 100.
#[cfg(feature = "http1")]
#[cfg_attr(docsrs, doc(cfg(feature = "http1")))]
pub fn http1_max_headers(&mut self, val: usize) -> &mut Self {
self.h1_builder.max_headers(val);
self
}

/// Set whether HTTP/0.9 responses should be tolerated.
///
/// Default is false.
Expand Down
20 changes: 20 additions & 0 deletions src/server/conn/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,26 @@ impl<E> Http1Builder<'_, E> {
self
}

/// Set the maximum number of headers.
///
/// When a request is received, the parser will reserve a buffer to store headers for optimal
/// performance.
///
/// If server receives more headers than the buffer size, it responds to the client with
/// "431 Request Header Fields Too Large".
///
/// The headers is allocated on the stack by default, which has higher performance. After
/// setting this value, headers will be allocated in heap memory, that is, heap memory
/// allocation will occur for each request, and there will be a performance drop of about 5%.
///
/// Note that this setting does not affect HTTP/2.
///
/// Default is 100.
pub fn max_headers(&mut self, val: usize) -> &mut Self {
self.inner.http1.max_headers(val);
self
}

/// Set a timeout for reading client request headers. If a client does not
/// transmit the entire header within this time, the connection is closed.
///
Expand Down

0 comments on commit b040494

Please sign in to comment.