Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http1): add option allowng leading whitespaces before first header #3643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading