From c66f7b6d8d1d7481eee91d9ff898fd4eaddfdeea Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 26 Jan 2024 10:33:55 -0500 Subject: fix(ext/http): smarter handling of Accept-Encoding (#22130) --- cli/tests/unit/serve_test.ts | 7 +++++++ ext/http/http_next.rs | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index 9d06860e0..09bd86015 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -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) { diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index a58c5f09a..e8c7ffbcc 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -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, _ => (), } -- cgit v1.2.3