From 2babc08c17507f398988156a60f7e57d7fcec801 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Tue, 28 Nov 2023 13:46:20 -0800 Subject: [PATCH] LibWeb/MimeSniff: Add rules for identifying an unknown mime type This also implements the pattern matching algorithm since it's needed. --- Tests/LibWeb/TestMimeSniff.cpp | 59 +++++ .../Libraries/LibWeb/MimeSniff/Resource.cpp | 235 +++++++++++++++++- 2 files changed, 290 insertions(+), 4 deletions(-) diff --git a/Tests/LibWeb/TestMimeSniff.cpp b/Tests/LibWeb/TestMimeSniff.cpp index e28cb44c17..538a311f84 100644 --- a/Tests/LibWeb/TestMimeSniff.cpp +++ b/Tests/LibWeb/TestMimeSniff.cpp @@ -30,3 +30,62 @@ TEST_CASE(determine_computed_mime_type_given_no_sniff_is_unset) EXPECT_EQ(xml_mime_type, MUST(computed_mime_type.serialized())); } + +TEST_CASE(compute_unknown_mime_type) +{ + HashMap> mime_type_to_headers_map; + + mime_type_to_headers_map.set("application/octet-stream"sv, { "\x00"sv }); + mime_type_to_headers_map.set("text/html"sv, { + "\x09\x09"sv, + "\x20