Skip to content

Commit

Permalink
feat(server): add http1::Builder::ignore_invalid_headers(bool) opti…
Browse files Browse the repository at this point in the history
…on (#3824)

Enabling this option tells hyper to skip invalid header lines, instead of rejecting the request.
  • Loading branch information
GlenDC authored Jan 14, 2025
1 parent e981a91 commit 3817a79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ futures-channel = { version = "0.3", optional = true }
futures-util = { version = "0.3", default-features = false, optional = true }
h2 = { version = "0.4.2", optional = true }
http-body-util = { version = "0.1", optional = true }
httparse = { version = "1.8", optional = true }
httparse = { version = "1.9", optional = true }
httpdate = { version = "1.0", optional = true }
itoa = { version = "1", optional = true }
pin-project-lite = { version = "0.2.4", optional = true }
Expand Down
1 change: 0 additions & 1 deletion src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ where
self.io.set_write_strategy_flatten();
}

#[cfg(feature = "client")]
pub(crate) fn set_h1_parser_config(&mut self, parser_config: ParserConfig) {
self.state.h1_parser_config = parser_config;
}
Expand Down
16 changes: 16 additions & 0 deletions src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pin_project_lite::pin_project! {
/// to bind the built connection to a service.
#[derive(Clone, Debug)]
pub struct Builder {
h1_parser_config: httparse::ParserConfig,
timer: Time,
h1_half_close: bool,
h1_keep_alive: bool,
Expand Down Expand Up @@ -231,6 +232,7 @@ impl Builder {
/// Create a new connection builder.
pub fn new() -> Self {
Self {
h1_parser_config: Default::default(),
timer: Time::Empty,
h1_half_close: false,
h1_keep_alive: true,
Expand Down Expand Up @@ -274,6 +276,19 @@ impl Builder {
self
}

/// Set whether HTTP/1 connections will silently ignored malformed header lines.
///
/// If this is enabled and a header line does not start with a valid header
/// name, or does not include a colon at all, the line will be silently ignored
/// and no error will be reported.
///
/// Default is false.
pub fn ignore_invalid_headers(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.ignore_invalid_headers_in_requests(enabled);
self
}

/// Set whether to support preserving original header cases.
///
/// Currently, this will record the original cases received, and store them
Expand Down Expand Up @@ -426,6 +441,7 @@ impl Builder {
I: Read + Write + Unpin,
{
let mut conn = proto::Conn::new(io);
conn.set_h1_parser_config(self.h1_parser_config.clone());
conn.set_timer(self.timer.clone());
if !self.h1_keep_alive {
conn.disable_keep_alive();
Expand Down

1 comment on commit 3817a79

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'end_to_end'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 3817a79 Previous: e981a91 Ratio
http2_parallel_x10_req_10kb_100_chunks_adaptive_window 24213681 ns/iter (± 25410939.09) 7650020 ns/iter (± 341895.53) 3.17

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.