diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-22 23:54:23 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-22 23:34:32 +0000 |
commit | 652676fdc101cebbafcafd230047027625ec1d70 (patch) | |
tree | c19ace259b2c9b0a873f861a9d84afe75de2f4ff /Userland | |
parent | 6a5c561a41d2591e9ca398ad75bc06066428d34a (diff) | |
download | serenity-652676fdc101cebbafcafd230047027625ec1d70.zip |
LibWeb: Make ResourceLoader insert a Content-Type header for file://
We make a guess using the MIME type guessing API in LibCore. This frees
clients of this code from having to do the guessing.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index f49ee4e81c..01edc9163f 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> * Copyright (c) 2022, Dexβͺ <dexes.ttp@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause @@ -9,6 +9,7 @@ #include <AK/Debug.h> #include <AK/JsonObject.h> #include <LibCore/ElapsedTimer.h> +#include <LibCore/MimeData.h> #include <LibWeb/Cookie/Cookie.h> #include <LibWeb/Cookie/ParsedCookie.h> #include <LibWeb/Loader/ContentFilter.h> @@ -268,7 +269,14 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has } auto data = maybe_data.release_value(); log_success(request); - success_callback(data, {}, {}); + + // NOTE: For file:// URLs, we have to guess the MIME type, since there's no HTTP header to tell us what this is. + // We insert a fake Content-Type header here, so that clients can use it to learn the MIME type. + HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> response_headers; + auto mime_type = Core::guess_mime_type_based_on_filename(request.url().path()); + response_headers.set("Content-Type"sv, mime_type); + + success_callback(data, response_headers, {}); }); m_page->client().request_file(move(file_request)); |