Skip to content

Commit c20c9cb

Browse files
committed
feat(http1): add option allowng leading whitespaces before first header
1 parent 226305d commit c20c9cb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/client/conn/http1.rs

+10
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ impl Builder {
387387
self
388388
}
389389

390+
/// Set whether HTTP/1 connections will allow white spaces before the first header,
391+
/// which is not allowed by spec.
392+
///
393+
/// Default is false.
394+
pub fn allow_whitespaces_before_first_header(&mut self, enabled: bool) -> &mut Builder {
395+
self.h1_parser_config
396+
.allow_whitespace_before_first_header_name(enabled);
397+
self
398+
}
399+
390400
/// Set whether HTTP/1 connections should try to use vectored writes,
391401
/// or always flatten into a single buffer.
392402
///

src/ffi/client.rs

+13
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ use super::task::{hyper_executor, hyper_task, hyper_task_return_type, AsTaskType
2121
/// - hyper_clientconn_options_set_preserve_header_case: Set whether header case is preserved.
2222
/// - hyper_clientconn_options_set_preserve_header_order: Set whether header order is preserved.
2323
/// - hyper_clientconn_options_http1_allow_multiline_headers: Set whether HTTP/1 connections accept obsolete line folding for header values.
24+
/// - hyper_client_conn_options_http1_allow_whitespaces_before_first_header: Set whether HTTP/1 connections accept leading whitespaces before first header.
2425
/// - hyper_clientconn_options_free: Free a set of HTTP clientconn options.
2526
pub struct hyper_clientconn_options {
2627
http1_allow_obsolete_multiline_headers_in_responses: bool,
28+
http1_allow_whitespaces_before_first_header: bool,
2729
http1_preserve_header_case: bool,
2830
http1_preserve_header_order: bool,
2931
http2: bool,
@@ -116,6 +118,7 @@ ffi_fn! {
116118

117119
conn::http1::Builder::new()
118120
.allow_obsolete_multiline_headers_in_responses(options.http1_allow_obsolete_multiline_headers_in_responses)
121+
.allow_whitespace_before_first_header_name(opts.http1_allow_whitespaces_before_first_header)
119122
.preserve_header_case(options.http1_preserve_header_case)
120123
.preserve_header_order(options.http1_preserve_header_order)
121124
.handshake::<_, crate::body::Incoming>(io)
@@ -272,4 +275,14 @@ ffi_fn! {
272275
opts.http1_allow_obsolete_multiline_headers_in_responses = enabled != 0;
273276
hyper_code::HYPERE_OK
274277
}
278+
279+
/// Set whether HTTP/1 connections accept leading whitespaces before first header.
280+
///
281+
/// Pass `0` to disable, `1` to enable.
282+
///
283+
fn hyper_clientconn_options_http1_allow_whitespaces_before_first_header(opts: *mut hyper_clientconn_options, enabled: c_int) -> hyper_code {
284+
let opts = non_null! { &mut *opts ?= hyper_code::HYPERE_INVALID_ARG };
285+
opts.http1_allow_whitespaces_before_first_header = enabled != 0;
286+
hyper_code::HYPERE_OK
287+
}
275288
}

0 commit comments

Comments
 (0)