Skip to content

Commit 3817a79

Browse files
authored
feat(server): add http1::Builder::ignore_invalid_headers(bool) option (#3824)
Enabling this option tells hyper to skip invalid header lines, instead of rejecting the request.
1 parent e981a91 commit 3817a79

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ futures-channel = { version = "0.3", optional = true }
3131
futures-util = { version = "0.3", default-features = false, optional = true }
3232
h2 = { version = "0.4.2", optional = true }
3333
http-body-util = { version = "0.1", optional = true }
34-
httparse = { version = "1.8", optional = true }
34+
httparse = { version = "1.9", optional = true }
3535
httpdate = { version = "1.0", optional = true }
3636
itoa = { version = "1", optional = true }
3737
pin-project-lite = { version = "0.2.4", optional = true }

src/proto/h1/conn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ where
115115
self.io.set_write_strategy_flatten();
116116
}
117117

118-
#[cfg(feature = "client")]
119118
pub(crate) fn set_h1_parser_config(&mut self, parser_config: ParserConfig) {
120119
self.state.h1_parser_config = parser_config;
121120
}

src/server/conn/http1.rs

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pin_project_lite::pin_project! {
6969
/// to bind the built connection to a service.
7070
#[derive(Clone, Debug)]
7171
pub struct Builder {
72+
h1_parser_config: httparse::ParserConfig,
7273
timer: Time,
7374
h1_half_close: bool,
7475
h1_keep_alive: bool,
@@ -231,6 +232,7 @@ impl Builder {
231232
/// Create a new connection builder.
232233
pub fn new() -> Self {
233234
Self {
235+
h1_parser_config: Default::default(),
234236
timer: Time::Empty,
235237
h1_half_close: false,
236238
h1_keep_alive: true,
@@ -274,6 +276,19 @@ impl Builder {
274276
self
275277
}
276278

279+
/// Set whether HTTP/1 connections will silently ignored malformed header lines.
280+
///
281+
/// If this is enabled and a header line does not start with a valid header
282+
/// name, or does not include a colon at all, the line will be silently ignored
283+
/// and no error will be reported.
284+
///
285+
/// Default is false.
286+
pub fn ignore_invalid_headers(&mut self, enabled: bool) -> &mut Builder {
287+
self.h1_parser_config
288+
.ignore_invalid_headers_in_requests(enabled);
289+
self
290+
}
291+
277292
/// Set whether to support preserving original header cases.
278293
///
279294
/// Currently, this will record the original cases received, and store them
@@ -426,6 +441,7 @@ impl Builder {
426441
I: Read + Write + Unpin,
427442
{
428443
let mut conn = proto::Conn::new(io);
444+
conn.set_h1_parser_config(self.h1_parser_config.clone());
429445
conn.set_timer(self.timer.clone());
430446
if !self.h1_keep_alive {
431447
conn.disable_keep_alive();

0 commit comments

Comments
 (0)