Merge pull request #7550 from influxdata/idpe-17449/content-encoding-identity
fix(idpe-17449): content-encoding identitypull/24376/head
commit
42b5f6d517
|
@ -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(_)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue