Skip to content

Commit

Permalink
move invalid h1 req header support to server
Browse files Browse the repository at this point in the history
bit silly to have it in client
  • Loading branch information
GlenDC committed Jan 10, 2025
1 parent 34e6a30 commit cf86089
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 1 addition & 14 deletions rama-http-core/src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
17 changes: 17 additions & 0 deletions rama-http-core/src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit cf86089

Please sign in to comment.