mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-23 10:50:49 +00:00
LibWeb/Fetch: Use MimeType in DataURL
This commit is contained in:
parent
2b59ba19e0
commit
295c4ef51a
Notes:
sideshowbarker
2024-07-17 09:37:30 +09:00
Author: https://github.com/jamierocks
Commit: 295c4ef51a
Pull-request: https://github.com/SerenityOS/serenity/pull/24525
5 changed files with 21 additions and 19 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/URL.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
#include <Userland/Libraries/LibWeb/Infra/Base64.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
@ -95,16 +96,17 @@ ErrorOr<DataURL> process_data_url(URL::URL const& data_url)
|
|||
mime_type = builder.string_view();
|
||||
}
|
||||
|
||||
// FIXME: Parse the MIME type's components according to https://mimesniff.spec.whatwg.org/#parse-a-mime-type
|
||||
// FIXME: 13. Let mimeTypeRecord be the result of parsing mimeType.
|
||||
auto mime_type_record = mime_type.trim("\n\r\t "sv, TrimMode::Both);
|
||||
// 13. Let mimeTypeRecord be the result of parsing mimeType.
|
||||
auto mime_type_record = TRY(MimeSniff::MimeType::parse(mime_type));
|
||||
|
||||
// 14. If mimeTypeRecord is failure, then set mimeTypeRecord to text/plain;charset=US-ASCII.
|
||||
if (mime_type_record.is_empty())
|
||||
mime_type_record = "text/plain;charset=US-ASCII"sv;
|
||||
if (!mime_type_record.has_value()) {
|
||||
mime_type_record = TRY(MimeSniff::MimeType::create("text"_string, "plain"_string));
|
||||
TRY(mime_type_record->set_parameter("charset"_string, "US-ASCII"_string));
|
||||
}
|
||||
|
||||
// 15. Return a new data: URL struct whose MIME type is mimeTypeRecord and body is body.
|
||||
return DataURL { TRY(String::from_utf8(mime_type_record)), body };
|
||||
return DataURL { mime_type_record.release_value(), body };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibURL/Forward.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
|
@ -39,7 +40,7 @@ inline constexpr Array FETCH_SCHEMES = {
|
|||
|
||||
// https://fetch.spec.whatwg.org/#data-url-struct
|
||||
struct DataURL {
|
||||
String mime_type;
|
||||
MimeSniff::MimeType mime_type;
|
||||
ByteBuffer body;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue