Skip to content

Commit

Permalink
feat(http1): add option allowng leading whitespaces before first header
Browse files Browse the repository at this point in the history
  • Loading branch information
dswij committed Apr 22, 2024
1 parent 226305d commit 05a280d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ impl Builder {
self
}

/// Set whether HTTP/1 connections will allow spaces before the first header,
/// which is not allowed by spec.
///
/// Default is false.
pub fn allow_spaces_before_first_header_name(&mut self, enabled: bool) -> &mut Builder {
self.h1_parser_config
.allow_space_before_first_header_name(enabled);
self
}

/// Set whether HTTP/1 connections should try to use vectored writes,
/// or always flatten into a single buffer.
///
Expand Down
16 changes: 16 additions & 0 deletions src/ffi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ use super::task::{hyper_executor, hyper_task, hyper_task_return_type, AsTaskType
/// - hyper_clientconn_options_set_preserve_header_case: Set whether header case is preserved.
/// - hyper_clientconn_options_set_preserve_header_order: Set whether header order is preserved.
/// - hyper_clientconn_options_http1_allow_multiline_headers: Set whether HTTP/1 connections accept obsolete line folding for header values.
/// - hyper_client_conn_options_http1_allow_spaces_before_first_header: Set whether HTTP/1 connections accept leading whitespaces before first header.
/// - hyper_clientconn_options_free: Free a set of HTTP clientconn options.
pub struct hyper_clientconn_options {
http1_allow_obsolete_multiline_headers_in_responses: bool,
http1_allow_spaces_before_first_header_name: bool,
http1_preserve_header_case: bool,
http1_preserve_header_order: bool,
http2: bool,
Expand Down Expand Up @@ -116,6 +118,7 @@ ffi_fn! {

conn::http1::Builder::new()
.allow_obsolete_multiline_headers_in_responses(options.http1_allow_obsolete_multiline_headers_in_responses)
.allow_spaces_before_first_header_name(options.http1_allow_spaces_before_first_header_name)
.preserve_header_case(options.http1_preserve_header_case)
.preserve_header_order(options.http1_preserve_header_order)
.handshake::<_, crate::body::Incoming>(io)
Expand Down Expand Up @@ -272,4 +275,17 @@ ffi_fn! {
opts.http1_allow_obsolete_multiline_headers_in_responses = enabled != 0;
hyper_code::HYPERE_OK
}

}

ffi_fn! {
/// Set whether HTTP/1 connections accept leading whitespaces before first header.
///
/// Pass `0` to disable, `1` to enable.
///
fn hyper_clientconn_options_http1_allow_spaces_before_first_header_name(opts: *mut hyper_clientconn_options, enabled: c_int) -> hyper_code {
let opts = non_null! { &mut *opts ?= hyper_code::HYPERE_INVALID_ARG };
opts.http1_allow_spaces_before_first_header_name = enabled != 0;
hyper_code::HYPERE_OK
}
}

0 comments on commit 05a280d

Please sign in to comment.