mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +00:00
LibWeb/MimeSniff: Port MimeType to new String
This commit is contained in:
parent
fabea2a6a7
commit
2d7ce38ee2
7 changed files with 86 additions and 71 deletions
|
@ -322,7 +322,7 @@ Optional<MimeSniff::MimeType> HeaderList::extract_mime_type() const
|
|||
// 6. For each value of values:
|
||||
for (auto const& value : *values) {
|
||||
// 1. Let temporaryMimeType be the result of parsing value.
|
||||
auto temporary_mime_type = MimeSniff::MimeType::parse(value);
|
||||
auto temporary_mime_type = MimeSniff::MimeType::parse(value).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 2. If temporaryMimeType is failure or its essence is "*/*", then continue.
|
||||
if (!temporary_mime_type.has_value() || temporary_mime_type->essence() == "*/*"sv)
|
||||
|
@ -339,14 +339,14 @@ Optional<MimeSniff::MimeType> HeaderList::extract_mime_type() const
|
|||
// 2. If mimeType’s parameters["charset"] exists, then set charset to mimeType’s parameters["charset"].
|
||||
auto it = mime_type->parameters().find("charset"sv);
|
||||
if (it != mime_type->parameters().end())
|
||||
charset = String::from_deprecated_string(it->value).release_value_but_fixme_should_propagate_errors();
|
||||
charset = it->value;
|
||||
|
||||
// 3. Set essence to mimeType’s essence.
|
||||
essence = String::from_deprecated_string(mime_type->essence()).release_value_but_fixme_should_propagate_errors();
|
||||
essence = mime_type->essence();
|
||||
}
|
||||
// 5. Otherwise, if mimeType’s parameters["charset"] does not exist, and charset is non-null, set mimeType’s parameters["charset"] to charset.
|
||||
else if (!mime_type->parameters().contains("charset"sv) && charset.has_value()) {
|
||||
mime_type->set_parameter("charset"sv, charset->to_deprecated_string());
|
||||
mime_type->set_parameter("charset"_string.release_value_but_fixme_should_propagate_errors(), charset.release_value()).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ bool is_cors_safelisted_request_header(Header const& header)
|
|||
return false;
|
||||
|
||||
// 2. Let mimeType be the result of parsing the result of isomorphic decoding value.
|
||||
auto mime_type = MimeSniff::MimeType::parse(StringView { value });
|
||||
auto mime_type = MimeSniff::MimeType::parse(StringView { value }).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
// 3. If mimeType is failure, then return false.
|
||||
if (!mime_type.has_value())
|
||||
|
|
|
@ -24,7 +24,7 @@ RequestOrResponseBlocking should_response_to_request_be_blocked_due_to_its_mime_
|
|||
// 4. If destination is script-like and one of the following is true, then return blocked:
|
||||
if (request.destination_is_script_like() && (
|
||||
// - mimeType’s essence starts with "audio/", "image/", or "video/".
|
||||
any_of(Array { "audio/"sv, "image/"sv, "video/"sv }, [&](auto prefix) { return mime_type->essence().starts_with(prefix); })
|
||||
any_of(Array { "audio/"sv, "image/"sv, "video/"sv }, [&](auto prefix) { return mime_type->essence().starts_with_bytes(prefix); })
|
||||
// - mimeType’s essence is "text/csv".
|
||||
|| mime_type->essence() == "text/csv"sv)) {
|
||||
return RequestOrResponseBlocking::Blocked;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue