From b1d10671b98aac479bf16609f31fe70ee28eed7b Mon Sep 17 00:00:00 2001 From: wiedld Date: Thu, 13 Apr 2023 16:55:53 -0700 Subject: [PATCH 1/2] fix(idpe-17449): accept content-encoding identity as a valid header --- ioxd_common/src/http/utils.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ioxd_common/src/http/utils.rs b/ioxd_common/src/http/utils.rs index e82499e429..1b65ee752f 100644 --- a/ioxd_common/src/http/utils.rs +++ b/ioxd_common/src/http/utils.rs @@ -59,6 +59,7 @@ pub async fn parse_body( })?; match content_encoding { "gzip" => true, + "identity" => false, _ => InvalidContentEncodingSnafu { content_encoding }.fail()?, } } @@ -124,6 +125,8 @@ mod tests { use super::*; + const MAX_BYTES: usize = 1024; + #[tokio::test] async fn client_hangup_during_parse() { #[derive(Debug, Snafu)] @@ -154,8 +157,6 @@ mod tests { #[tokio::test] async fn test_read_gzipped_body_truncation() { - const MAX_BYTES: usize = 1024; - // Generate a LP string in the form of: // // bananas,A=AAAAAAAAAA(repeated)... B=42 @@ -199,4 +200,16 @@ mod tests { Err(ParseBodyError::RequestSizeExceeded { .. }) )); } + + #[tokio::test] + async fn test_accept_identity_content_encoding() { + let request = Request::builder() + .uri("https://explosions.example/") + .header("Content-Encoding", "identity") + .body(Body::from("bananas,A=12")) + .unwrap(); + + let got = parse_body(request, MAX_BYTES).await; + assert!(matches!(got, Ok(_))); + } } From ca492b09d266346c7640c9326365fca2ba66ac20 Mon Sep 17 00:00:00 2001 From: wiedld Date: Thu, 13 Apr 2023 16:56:39 -0700 Subject: [PATCH 2/2] fix(idpe-17449): accept content-encoding identity for the parseBody --- router/src/server/http.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/router/src/server/http.rs b/router/src/server/http.rs index 928c4b52a7..fd5440b17c 100644 --- a/router/src/server/http.rs +++ b/router/src/server/http.rs @@ -498,7 +498,7 @@ where .map(|v| v.to_str().map_err(Error::NonUtf8ContentHeader)) .transpose()?; let ungzip = match encoding { - None => false, + None | Some("identity") => false, Some("gzip") => true, Some(v) => return Err(Error::InvalidContentEncoding(v.to_string())), }; @@ -620,7 +620,7 @@ mod tests { want_result = $want_result:pat, // Expected handler return value (as pattern) want_dml_calls = $($want_dml_calls:tt )+ // assert_matches slice pattern for expected DML calls ) => { - // Generate the two test cases by feed the same inputs, but varying + // Generate the three test cases by feed the same inputs, but varying // the encoding. test_http_handler!( $name, @@ -632,6 +632,16 @@ mod tests { want_result = $want_result, want_dml_calls = $($want_dml_calls)+ ); + test_http_handler!( + $name, + encoding=identity, + uri = $uri, + body = $body, + dml_write_handler = $dml_write_handler, + dml_delete_handler = $dml_delete_handler, + want_result = $want_result, + want_dml_calls = $($want_dml_calls)+ + ); test_http_handler!( $name, encoding=gzip, @@ -715,6 +725,9 @@ mod tests { (encoding=plain, $body:ident) => { $body }; + (encoding=identity, $body:ident) => { + $body + }; (encoding=gzip, $body:ident) => {{ // Apply gzip compression to the body let mut e = GzEncoder::new(Vec::new(), Compression::default()); @@ -722,6 +735,12 @@ mod tests { e.finish().expect("failed to compress test body") }}; (encoding_header=plain, $request:ident) => {}; + (encoding_header=identity, $request:ident) => {{ + // Set the identity content encoding + $request + .headers_mut() + .insert(CONTENT_ENCODING, HeaderValue::from_static("identity")); + }}; (encoding_header=gzip, $request:ident) => {{ // Set the gzip content encoding $request