fix(ext/http): smarter handling of Accept-Encoding (#22130)

This commit is contained in:
Matt Mastracci 2024-01-26 10:33:55 -05:00 committed by GitHub
parent 98c537726e
commit c66f7b6d8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View file

@ -2649,6 +2649,13 @@ const compressionTestCases = [
out: { "Content-Type": "text/plain", "Cache-Control": "no-transform" },
expect: null,
},
{
name: "BadHeader",
length: 1024,
in: { "Accept-Encoding": "\x81" },
out: { "Content-Type": "text/plain", "Cache-Control": "no-transform" },
expect: null,
},
];
for (const testCase of compressionTestCases) {

View file

@ -558,11 +558,11 @@ fn is_request_compressible(
return Compression::None;
};
match accept_encoding.to_str().unwrap() {
match accept_encoding.to_str() {
// Firefox and Chrome send this -- no need to parse
"gzip, deflate, br" => return Compression::Brotli,
"gzip" => return Compression::GZip,
"br" => return Compression::Brotli,
Ok("gzip, deflate, br") => return Compression::Brotli,
Ok("gzip") => return Compression::GZip,
Ok("br") => return Compression::Brotli,
_ => (),
}