diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/Loader')
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/Resource.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/Resource.cpp b/Userland/Libraries/LibWeb/Loader/Resource.cpp index 9231ec341e..0892cc61c9 100644 --- a/Userland/Libraries/LibWeb/Loader/Resource.cpp +++ b/Userland/Libraries/LibWeb/Loader/Resource.cpp @@ -41,7 +41,7 @@ void Resource::for_each_client(Function<void(ResourceClient&)> callback) } } -static String encoding_from_content_type(const String& content_type) +static Optional<String> encoding_from_content_type(const String& content_type) { auto offset = content_type.index_of("charset="); if (offset.has_value()) { @@ -53,7 +53,7 @@ static String encoding_from_content_type(const String& content_type) return encoding; } - return "utf-8"; + return {}; } static String mime_type_from_content_type(const String& content_type) @@ -74,20 +74,28 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap m_loaded = true; auto content_type = headers.get("Content-Type"); + if (content_type.has_value()) { dbgln_if(RESOURCE_DEBUG, "Content-Type header: '{}'", content_type.value()); - m_encoding = encoding_from_content_type(content_type.value()); m_mime_type = mime_type_from_content_type(content_type.value()); } else if (url().protocol() == "data" && !url().data_mime_type().is_empty()) { dbgln_if(RESOURCE_DEBUG, "This is a data URL with mime-type _{}_", url().data_mime_type()); - m_encoding = "utf-8"; // FIXME: This doesn't seem nice. m_mime_type = url().data_mime_type(); } else { - dbgln_if(RESOURCE_DEBUG, "No Content-Type header to go on! Guessing based on filename..."); - m_encoding = "utf-8"; // FIXME: This doesn't seem nice. m_mime_type = Core::guess_mime_type_based_on_filename(url().path()); } + if (content_type.has_value()) { + auto encoding = encoding_from_content_type(content_type.value()); + if (encoding.has_value()) { + dbgln_if(RESOURCE_DEBUG, "Set encoding '{}' from Content-Type", encoding.has_value()); + m_encoding = encoding.value(); + } else { + // FIXME: This doesn't seem nice. + m_encoding = "utf-8"; + } + } + for_each_client([](auto& client) { client.resource_did_load(); }); |