Skip to content

Commit

Permalink
Add config option to set http1_ignore_invalid_headers_in_responses
Browse files Browse the repository at this point in the history
  • Loading branch information
sujeebant committed Aug 9, 2023
1 parent 8396233 commit 9b3fa9f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mime_guess = { version = "2.0", default-features = false, optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
encoding_rs = "0.8"
http-body = "0.4.0"
hyper = { version = "0.14.18", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
hyper = { version = "0.14.21", default-features = false, features = ["tcp", "http1", "http2", "client", "runtime"] }
h2 = "0.3.10"
once_cell = "1"
log = "0.4"
Expand Down
16 changes: 16 additions & 0 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct Config {
http09_responses: bool,
http1_title_case_headers: bool,
http1_allow_obsolete_multiline_headers_in_responses: bool,
http1_ignore_invalid_headers_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 @@ -201,6 +202,7 @@ impl ClientBuilder {
http09_responses: false,
http1_title_case_headers: false,
http1_allow_obsolete_multiline_headers_in_responses: false,
http1_ignore_invalid_headers_in_responses: false,
http2_initial_stream_window_size: None,
http2_initial_connection_window_size: None,
http2_adaptive_window: false,
Expand Down Expand Up @@ -620,6 +622,10 @@ impl ClientBuilder {
builder.http1_allow_obsolete_multiline_headers_in_responses(true);
}

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

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

Ok(Client {
Expand Down Expand Up @@ -1015,6 +1021,12 @@ impl ClientBuilder {
self
}

/// Sets whether invalid header lines should be silently ignored in HTTP/1 responses.
pub fn http1_ignore_invalid_headers_in_responses(mut self, value: bool) -> ClientBuilder {
self.config.http1_ignore_invalid_headers_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 @@ -1873,6 +1885,10 @@ impl Config {
f.field("http1_allow_obsolete_multiline_headers_in_responses", &true);
}

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

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

/// Sets whether invalid header lines should be silently ignored in HTTP/1 responses.
pub fn http1_ignore_invalid_headers_in_responses(self, value: bool) -> ClientBuilder {
self.with_inner(|inner| inner.http1_ignore_invalid_headers_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 9b3fa9f

Please sign in to comment.