From 7bafab86339f903decb7892a126eb174e379f92c Mon Sep 17 00:00:00 2001 From: Sujeeban Thuraisamy Date: Tue, 8 Aug 2023 11:36:10 +0200 Subject: [PATCH] Add config option to set http1_allow_spaces_after_header_name_in_responses --- src/async_impl/client.rs | 24 ++++++++++++++++++++++++ src/blocking/client.rs | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 8fa363c58..bd7a877c6 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -120,6 +120,7 @@ struct Config { http09_responses: bool, http1_title_case_headers: bool, http1_allow_obsolete_multiline_headers_in_responses: bool, + http1_allow_spaces_after_header_name_in_responses: bool, http2_initial_stream_window_size: Option, http2_initial_connection_window_size: Option, http2_adaptive_window: bool, @@ -201,6 +202,7 @@ impl ClientBuilder { http09_responses: false, http1_title_case_headers: false, http1_allow_obsolete_multiline_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, @@ -620,6 +622,10 @@ impl ClientBuilder { builder.http1_allow_obsolete_multiline_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 { @@ -1015,6 +1021,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; @@ -1873,6 +1893,10 @@ impl Config { f.field("http1_allow_obsolete_multiline_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); } diff --git a/src/blocking/client.rs b/src/blocking/client.rs index e6ec6735a..f40ae6b75 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -420,6 +420,15 @@ impl ClientBuilder { self.with_inner(|inner| inner.http1_allow_obsolete_multiline_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())