From 2dca8526906481db340abf25bedfacb90038472a Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 29 Nov 2023 17:03:42 -0800 Subject: [PATCH] Add accept encoding test without qvalues --- src/subcommand/server/accept_encoding.rs | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/subcommand/server/accept_encoding.rs b/src/subcommand/server/accept_encoding.rs index be693edd44..7058fd2c19 100644 --- a/src/subcommand/server/accept_encoding.rs +++ b/src/subcommand/server/accept_encoding.rs @@ -67,7 +67,7 @@ mod tests { } #[tokio::test] - async fn accepts_encoding() { + async fn accepts_encoding_with_qvalues() { let req = Request::builder() .header(ACCEPT_ENCODING, "deflate;q=0.5, gzip;q=1.0, br;q=0.8") .body(()) @@ -90,7 +90,30 @@ mod tests { assert!(encodings.is_acceptable(&HeaderValue::from_static("deflate"))); assert!(encodings.is_acceptable(&HeaderValue::from_static("gzip"))); assert!(encodings.is_acceptable(&HeaderValue::from_static("br"))); + assert!(!encodings.is_acceptable(&HeaderValue::from_static("bzip2"))); + } + + #[tokio::test] + async fn accepts_encoding_without_qvalues() { + let req = Request::builder() + .header(ACCEPT_ENCODING, "gzip, deflate, br") + .body(()) + .unwrap(); + + let encodings = AcceptEncoding::from_request_parts( + &mut req.into_parts().0, + &Arc::new(ServerConfig { + is_json_api_enabled: false, + }), + ) + .await + .unwrap(); + + assert_eq!(encodings.0, Some("gzip, deflate, br".to_string())); + assert!(encodings.is_acceptable(&HeaderValue::from_static("deflate"))); + assert!(encodings.is_acceptable(&HeaderValue::from_static("gzip"))); + assert!(encodings.is_acceptable(&HeaderValue::from_static("br"))); assert!(!encodings.is_acceptable(&HeaderValue::from_static("bzip2"))); } }