From cf86089ce955c97a14437c26aea4ddcf434cb700 Mon Sep 17 00:00:00 2001 From: Glen De Cauwsemaecker Date: Fri, 10 Jan 2025 22:54:14 +0100 Subject: [PATCH] move invalid h1 req header support to server bit silly to have it in client --- rama-http-core/src/client/conn/http1.rs | 15 +-------------- rama-http-core/src/server/conn/http1.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/rama-http-core/src/client/conn/http1.rs b/rama-http-core/src/client/conn/http1.rs index 587bad05..0424f4c9 100644 --- a/rama-http-core/src/client/conn/http1.rs +++ b/rama-http-core/src/client/conn/http1.rs @@ -390,25 +390,12 @@ impl Builder { /// and no error will be reported. /// /// Default is false. - pub fn ignore_invalid_headers_in_responses(&mut self, enabled: bool) -> &mut Builder { + pub fn ignore_invalid_headers(&mut self, enabled: bool) -> &mut Builder { self.h1_parser_config .ignore_invalid_headers_in_responses(enabled); 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_in_requests(&mut self, enabled: bool) -> &mut Builder { - self.h1_parser_config - .ignore_invalid_headers_in_requests(enabled); - self - } - /// Set whether HTTP/1 connections should try to use vectored writes, /// or always flatten into a single buffer. /// diff --git a/rama-http-core/src/server/conn/http1.rs b/rama-http-core/src/server/conn/http1.rs index 5a643d2c..f41bfa53 100644 --- a/rama-http-core/src/server/conn/http1.rs +++ b/rama-http-core/src/server/conn/http1.rs @@ -9,6 +9,7 @@ use std::time::Duration; use crate::upgrade::Upgraded; use bytes::Bytes; use futures_util::ready; +use httparse::ParserConfig; use tokio::io::{AsyncRead, AsyncWrite}; use crate::body::Incoming as IncomingBody; @@ -63,6 +64,7 @@ pin_project_lite::pin_project! { /// to bind the built connection to a service. #[derive(Clone, Debug)] pub struct Builder { + h1_parser_config: ParserConfig, h1_half_close: bool, h1_keep_alive: bool, h1_title_case_headers: bool, @@ -222,6 +224,7 @@ impl Builder { /// Create a new connection builder. pub fn new() -> Self { Self { + h1_parser_config: Default::default(), h1_half_close: false, h1_keep_alive: true, h1_title_case_headers: false, @@ -263,6 +266,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 the maximum number of headers. /// /// When a request is received, the parser will reserve a buffer to store headers for optimal @@ -363,6 +379,7 @@ impl Builder { I: AsyncRead + AsyncWrite + Send + Unpin + 'static, { let mut conn = proto::Conn::new(io); + conn.set_h1_parser_config(self.h1_parser_config.clone()); if !self.h1_keep_alive { conn.disable_keep_alive(); }