pub(crate) fn accept_encoding_for(major: u32) -> &'static str {
if major >= 123 {
"gzip, deflate, br, zstd"
} else {
"gzip, deflate, br"
}
}
pub(crate) fn accept_encoding_skew(binary_major: u32, claimed_major: u32) -> Option<&'static str> {
let claimed = accept_encoding_for(claimed_major);
(claimed != accept_encoding_for(binary_major)).then_some(claimed)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn accept_encoding_straddles_the_zstd_boundary() {
assert_eq!(accept_encoding_for(122), "gzip, deflate, br");
assert_eq!(accept_encoding_for(123), "gzip, deflate, br, zstd");
assert_eq!(accept_encoding_for(148), "gzip, deflate, br, zstd");
}
#[test]
fn accept_encoding_skew_flags_only_a_boundary_crossing() {
assert_eq!(accept_encoding_skew(148, 120), Some("gzip, deflate, br"));
assert_eq!(
accept_encoding_skew(120, 148),
Some("gzip, deflate, br, zstd")
);
assert_eq!(accept_encoding_skew(148, 140), None);
assert_eq!(accept_encoding_skew(120, 122), None);
assert_eq!(accept_encoding_skew(130, 130), None);
}
}