From c521b509d4c001adb7bca05db5f2e2eab041ad37 Mon Sep 17 00:00:00 2001 From: Glen De Cauwsemaecker Date: Thu, 9 Jan 2025 22:48:58 +0100 Subject: [PATCH] http1 expose ignore_invalid_headers_in_requests opt --- Cargo.toml | 2 +- src/server/conn/http1.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a6da142500..6a1895e745 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index 097497bf41..fe8a2c975c 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -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, @@ -274,6 +275,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 @@ -426,6 +440,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();