Skip to content

Commit 6f07b9f

Browse files
Add ClientBuilder::http1_ignore_invalid_headers_in_responses() (#1926)
Co-authored-by: Sujeeban Thuraisamy <[email protected]>
1 parent 8396233 commit 6f07b9f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mime_guess = { version = "2.0", default-features = false, optional = true }
100100
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
101101
encoding_rs = "0.8"
102102
http-body = "0.4.0"
103-
hyper = { version = "0.14.18", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
103+
hyper = { version = "0.14.21", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
104104
h2 = "0.3.10"
105105
once_cell = "1"
106106
log = "0.4"

src/async_impl/client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct Config {
120120
http09_responses: bool,
121121
http1_title_case_headers: bool,
122122
http1_allow_obsolete_multiline_headers_in_responses: bool,
123+
http1_ignore_invalid_headers_in_responses: bool,
123124
http2_initial_stream_window_size: Option<u32>,
124125
http2_initial_connection_window_size: Option<u32>,
125126
http2_adaptive_window: bool,
@@ -201,6 +202,7 @@ impl ClientBuilder {
201202
http09_responses: false,
202203
http1_title_case_headers: false,
203204
http1_allow_obsolete_multiline_headers_in_responses: false,
205+
http1_ignore_invalid_headers_in_responses: false,
204206
http2_initial_stream_window_size: None,
205207
http2_initial_connection_window_size: None,
206208
http2_adaptive_window: false,
@@ -620,6 +622,10 @@ impl ClientBuilder {
620622
builder.http1_allow_obsolete_multiline_headers_in_responses(true);
621623
}
622624

625+
if config.http1_ignore_invalid_headers_in_responses {
626+
builder.http1_ignore_invalid_headers_in_responses(true);
627+
}
628+
623629
let proxies_maybe_http_auth = proxies.iter().any(|p| p.maybe_has_http_auth());
624630

625631
Ok(Client {
@@ -1015,6 +1021,12 @@ impl ClientBuilder {
10151021
self
10161022
}
10171023

1024+
/// Sets whether invalid header lines should be silently ignored in HTTP/1 responses.
1025+
pub fn http1_ignore_invalid_headers_in_responses(mut self, value: bool) -> ClientBuilder {
1026+
self.config.http1_ignore_invalid_headers_in_responses = value;
1027+
self
1028+
}
1029+
10181030
/// Only use HTTP/1.
10191031
pub fn http1_only(mut self) -> ClientBuilder {
10201032
self.config.http_version_pref = HttpVersionPref::Http1;
@@ -1873,6 +1885,10 @@ impl Config {
18731885
f.field("http1_allow_obsolete_multiline_headers_in_responses", &true);
18741886
}
18751887

1888+
if self.http1_ignore_invalid_headers_in_responses {
1889+
f.field("http1_ignore_invalid_headers_in_responses", &true);
1890+
}
1891+
18761892
if matches!(self.http_version_pref, HttpVersionPref::Http1) {
18771893
f.field("http1_only", &true);
18781894
}

src/blocking/client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ impl ClientBuilder {
420420
self.with_inner(|inner| inner.http1_allow_obsolete_multiline_headers_in_responses(value))
421421
}
422422

423+
/// Sets whether invalid header lines should be silently ignored in HTTP/1 responses.
424+
pub fn http1_ignore_invalid_headers_in_responses(self, value: bool) -> ClientBuilder {
425+
self.with_inner(|inner| inner.http1_ignore_invalid_headers_in_responses(value))
426+
}
427+
423428
/// Only use HTTP/1.
424429
pub fn http1_only(self) -> ClientBuilder {
425430
self.with_inner(|inner| inner.http1_only())

0 commit comments

Comments
 (0)