Skip to content

Commit

Permalink
Add accept encoding test without qvalues (#2822)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 5, 2023
1 parent d06eaca commit 872973d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/subcommand/server/accept_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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")));
}
}

0 comments on commit 872973d

Please sign in to comment.