Skip to content

Commit

Permalink
Add `ClientBuilder::http1_allow_spaces_after_header_name_in_responses…
Browse files Browse the repository at this point in the history
…()` (#1932)

Co-authored-by: Sujeeban Thuraisamy <s.thuraisamy@qwant.com>
  • Loading branch information
T-Sujeeban and sujeebant authored Aug 9, 2023
1 parent 6f07b9f commit 1f6c2cf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct Config {
http1_title_case_headers: bool,
http1_allow_obsolete_multiline_headers_in_responses: bool,
http1_ignore_invalid_headers_in_responses: bool,
http1_allow_spaces_after_header_name_in_responses: bool,
http2_initial_stream_window_size: Option<u32>,
http2_initial_connection_window_size: Option<u32>,
http2_adaptive_window: bool,
Expand Down Expand Up @@ -203,6 +204,7 @@ impl ClientBuilder {
http1_title_case_headers: false,
http1_allow_obsolete_multiline_headers_in_responses: false,
http1_ignore_invalid_headers_in_responses: false,
http1_allow_spaces_after_header_name_in_responses: false,
http2_initial_stream_window_size: None,
http2_initial_connection_window_size: None,
http2_adaptive_window: false,
Expand Down Expand Up @@ -626,6 +628,10 @@ impl ClientBuilder {
builder.http1_ignore_invalid_headers_in_responses(true);
}

if config.http1_allow_spaces_after_header_name_in_responses {
builder.http1_allow_spaces_after_header_name_in_responses(true);
}

let proxies_maybe_http_auth = proxies.iter().any(|p| p.maybe_has_http_auth());

Ok(Client {
Expand Down Expand Up @@ -1027,6 +1033,20 @@ impl ClientBuilder {
self
}

/// Set whether HTTP/1 connections will accept spaces between header
/// names and the colon that follow them in responses.
///
/// Newline codepoints (`\r` and `\n`) will be transformed to spaces when
/// parsing.
pub fn http1_allow_spaces_after_header_name_in_responses(
mut self,
value: bool,
) -> ClientBuilder {
self.config
.http1_allow_spaces_after_header_name_in_responses = value;
self
}

/// Only use HTTP/1.
pub fn http1_only(mut self) -> ClientBuilder {
self.config.http_version_pref = HttpVersionPref::Http1;
Expand Down Expand Up @@ -1889,6 +1909,10 @@ impl Config {
f.field("http1_ignore_invalid_headers_in_responses", &true);
}

if self.http1_allow_spaces_after_header_name_in_responses {
f.field("http1_allow_spaces_after_header_name_in_responses", &true);
}

if matches!(self.http_version_pref, HttpVersionPref::Http1) {
f.field("http1_only", &true);
}
Expand Down
9 changes: 9 additions & 0 deletions src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ impl ClientBuilder {
self.with_inner(|inner| inner.http1_ignore_invalid_headers_in_responses(value))
}

/// Set whether HTTP/1 connections will accept spaces between header
/// names and the colon that follow them in responses.
///
/// Newline codepoints (\r and \n) will be transformed to spaces when
/// parsing.
pub fn http1_allow_spaces_after_header_name_in_responses(self, value: bool) -> ClientBuilder {
self.with_inner(|inner| inner.http1_allow_spaces_after_header_name_in_responses(value))
}

/// Only use HTTP/1.
pub fn http1_only(self) -> ClientBuilder {
self.with_inner(|inner| inner.http1_only())
Expand Down

0 comments on commit 1f6c2cf

Please sign in to comment.