LibWeb: Set Content-Type for data: URLs instead of checking MIME on load

This makes the loader more agnostic.

Additionally, this allows us to load tab in Ladybird with a 'data:' URL
containing parameters, as a Resource will now call
`mime_type_from_content_type` to extract the content type from MIME. :^)
This commit is contained in:
Karol Kosek 2023-07-06 19:25:35 +02:00 committed by Andreas Kling
parent 16836e7e62
commit f27b9b9563
Notes: sideshowbarker 2024-07-16 19:17:47 +09:00
2 changed files with 5 additions and 5 deletions

View file

@ -102,9 +102,6 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, HashMap<Depre
// Let's use image/x-qoi for now, which is also what our Core::MimeData uses & would guess.
if (m_mime_type == "application/octet-stream" && url().serialize_path().ends_with(".qoi"sv))
m_mime_type = "image/x-qoi";
} else if (url().scheme() == "data" && !url().data_mime_type().is_empty()) {
dbgln_if(RESOURCE_DEBUG, "This is a data URL with mime-type _{}_", url().data_mime_type());
m_mime_type = url().data_mime_type();
} else {
auto content_type_options = headers.get("X-Content-Type-Options");
if (content_type_options.value_or("").equals_ignoring_ascii_case("nosniff"sv)) {

View file

@ -223,9 +223,12 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
data = url.data_payload().to_byte_buffer();
}
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> response_headers;
response_headers.set("Content-Type", url.data_mime_type());
log_success(request);
Platform::EventLoopPlugin::the().deferred_invoke([data = move(data), success_callback = move(success_callback)] {
success_callback(data, {}, {});
Platform::EventLoopPlugin::the().deferred_invoke([data = move(data), response_headers = move(response_headers), success_callback = move(success_callback)] {
success_callback(data, response_headers, {});
});
return;
}