mirror of
https://github.com/actix/actix-web.git
synced 2024-06-13 02:39:32 +00:00
AcceptEncoding.{ranked,negotiate}() prefers brotli > zstd > gzip
This commit is contained in:
parent
e5ed406af6
commit
f82f05c6c9
|
@ -223,7 +223,11 @@ impl AcceptEncoding {
|
|||
// use stable sort so items with equal q-factor retain listed order
|
||||
types.sort_by(|a, b| {
|
||||
// sort by q-factor descending
|
||||
b.quality.cmp(&a.quality)
|
||||
if b.quality == a.quality {
|
||||
encoding_rank(b).cmp(&encoding_rank(a))
|
||||
} else {
|
||||
b.quality.cmp(&a.quality)
|
||||
}
|
||||
});
|
||||
|
||||
types.into_iter()
|
||||
|
@ -393,11 +397,11 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
test.negotiate([Encoding::gzip(), Encoding::brotli(), Encoding::identity()].iter()),
|
||||
Some(Encoding::gzip())
|
||||
Some(Encoding::brotli())
|
||||
);
|
||||
assert_eq!(
|
||||
test.negotiate([Encoding::brotli(), Encoding::gzip(), Encoding::identity()].iter()),
|
||||
Some(Encoding::gzip())
|
||||
Some(Encoding::brotli())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -414,6 +418,9 @@ mod tests {
|
|||
|
||||
let test = accept_encoding!("br", "gzip", "*");
|
||||
assert_eq!(test.ranked(), vec![enc("br"), enc("gzip"), enc("*")]);
|
||||
|
||||
let test = accept_encoding!("gzip", "br", "*");
|
||||
assert_eq!(test.ranked(), vec![enc("br"), enc("gzip"), enc("*")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -96,7 +96,7 @@ async fn negotiate_encoding_gzip() {
|
|||
|
||||
let req = srv
|
||||
.post("/static")
|
||||
.insert_header((header::ACCEPT_ENCODING, "gzip,br,zstd"))
|
||||
.insert_header((header::ACCEPT_ENCODING, "gzip"))
|
||||
.send();
|
||||
|
||||
let mut res = req.await.unwrap();
|
||||
|
@ -109,7 +109,7 @@ async fn negotiate_encoding_gzip() {
|
|||
let mut res = srv
|
||||
.post("/static")
|
||||
.no_decompress()
|
||||
.insert_header((header::ACCEPT_ENCODING, "gzip,br,zstd"))
|
||||
.insert_header((header::ACCEPT_ENCODING, "gzip"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -154,7 +154,7 @@ async fn negotiate_encoding_zstd() {
|
|||
|
||||
let req = srv
|
||||
.post("/static")
|
||||
.insert_header((header::ACCEPT_ENCODING, "zstd,gzip,br"))
|
||||
.insert_header((header::ACCEPT_ENCODING, "zstd,gzip"))
|
||||
.send();
|
||||
|
||||
let mut res = req.await.unwrap();
|
||||
|
@ -167,7 +167,7 @@ async fn negotiate_encoding_zstd() {
|
|||
let mut res = srv
|
||||
.post("/static")
|
||||
.no_decompress()
|
||||
.insert_header((header::ACCEPT_ENCODING, "zstd,gzip,br"))
|
||||
.insert_header((header::ACCEPT_ENCODING, "zstd,gzip"))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in a new issue