From 47992f7b39a69cbb927d281cdfd3e818af068bde Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Thu, 7 Nov 2024 16:00:40 +1100 Subject: [PATCH] LibWeb: Compute mimetype when loading a document computed type != supplied type --- Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 458bc4d116e..efc4c12fbec 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -398,10 +399,15 @@ JS::GCPtr load_document(HTML::NavigationParams const& navigation_ // and origin initiatorOrigin, perform the following steps. They return a Document or null. // 1. Let type be the computed type of navigationParams's response. - auto extracted_mime_type = navigation_params.response->header_list()->extract_mime_type(); - if (!extracted_mime_type.has_value()) - return nullptr; - auto type = extracted_mime_type.release_value(); + auto supplied_type = navigation_params.response->header_list()->extract_mime_type(); + auto type = MimeSniff::Resource::sniff( + navigation_params.response->body()->source().visit( + [](Empty) { return ReadonlyBytes {}; }, + [](ByteBuffer const& buffer) { return ReadonlyBytes { buffer }; }, + [](JS::Handle const& blob) { return blob->raw_bytes(); }), + MimeSniff::SniffingConfiguration { + .sniffing_context = MimeSniff::SniffingContext::Browsing, + .supplied_type = move(supplied_type) }); VERIFY(navigation_params.response->body());