summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Fetch/Infrastructure
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-03-03 09:27:51 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-03 11:02:21 +0000
commitad4b4046f4503a54b5762f97381cc7b8d90402fc (patch)
treeeaad349beb092eadc1ae7d01e9e0f0ae6cdbddfa /Userland/Libraries/LibWeb/Fetch/Infrastructure
parent2d7ce38ee210ee99d3d896e5a453ef6a214da374 (diff)
downloadserenity-ad4b4046f4503a54b5762f97381cc7b8d90402fc.zip
LibWeb/Fetch: Propagate OOM errors from HeaderList::extract_mime_type()
Diffstat (limited to 'Userland/Libraries/LibWeb/Fetch/Infrastructure')
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h2
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h4
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp4
5 files changed, 13 insertions, 13 deletions
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp
index c65c7e2be7..d124e40490 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp
@@ -298,7 +298,7 @@ ErrorOr<Vector<Header>> HeaderList::sort_and_combine() const
}
// https://fetch.spec.whatwg.org/#concept-header-extract-mime-type
-Optional<MimeSniff::MimeType> HeaderList::extract_mime_type() const
+ErrorOr<Optional<MimeSniff::MimeType>> HeaderList::extract_mime_type() const
{
// 1. Let charset be null.
Optional<String> charset;
@@ -312,17 +312,17 @@ Optional<MimeSniff::MimeType> HeaderList::extract_mime_type() const
// 4. Let values be the result of getting, decoding, and splitting `Content-Type` from headers.
auto values_or_error = get_decode_and_split("Content-Type"sv.bytes());
if (values_or_error.is_error())
- return {};
+ return OptionalNone {};
auto values = values_or_error.release_value();
// 5. If values is null, then return failure.
if (!values.has_value())
- return {};
+ return OptionalNone {};
// 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).release_value_but_fixme_should_propagate_errors();
+ auto temporary_mime_type = TRY(MimeSniff::MimeType::parse(value));
// 2. If temporaryMimeType is failure or its essence is "*/*", then continue.
if (!temporary_mime_type.has_value() || temporary_mime_type->essence() == "*/*"sv)
@@ -346,7 +346,7 @@ Optional<MimeSniff::MimeType> HeaderList::extract_mime_type() const
}
// 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"_string.release_value_but_fixme_should_propagate_errors(), charset.release_value()).release_value_but_fixme_should_propagate_errors();
+ TRY(mime_type->set_parameter(TRY("charset"_string), charset.release_value()));
}
}
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h
index 1bfd06d9b5..61bfc85e48 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h
@@ -51,7 +51,7 @@ public:
[[nodiscard]] ErrorOr<void> set(Header);
[[nodiscard]] ErrorOr<void> combine(Header);
[[nodiscard]] ErrorOr<Vector<Header>> sort_and_combine() const;
- [[nodiscard]] Optional<MimeSniff::MimeType> extract_mime_type() const;
+ [[nodiscard]] ErrorOr<Optional<MimeSniff::MimeType>> extract_mime_type() const;
};
struct RangeHeaderValue {
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.cpp
index b7c05b8f81..f17db8e2cc 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -11,10 +11,10 @@
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#ref-for-should-response-to-request-be-blocked-due-to-mime-type?
-RequestOrResponseBlocking should_response_to_request_be_blocked_due_to_its_mime_type(Response const& response, Request const& request)
+ErrorOr<RequestOrResponseBlocking> should_response_to_request_be_blocked_due_to_its_mime_type(Response const& response, Request const& request)
{
// 1. Let mimeType be the result of extracting a MIME type from response’s header list.
- auto mime_type = response.header_list()->extract_mime_type();
+ auto mime_type = TRY(response.header_list()->extract_mime_type());
// 2. If mimeType is failure, then return allowed.
if (!mime_type.has_value())
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h
index 96c81a1b97..b5c630ab31 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -11,6 +11,6 @@
namespace Web::Fetch::Infrastructure {
-[[nodiscard]] RequestOrResponseBlocking should_response_to_request_be_blocked_due_to_its_mime_type(Response const&, Request const&);
+ErrorOr<RequestOrResponseBlocking> should_response_to_request_be_blocked_due_to_its_mime_type(Response const&, Request const&);
}
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp
index 1d762df730..23401c04fb 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -38,7 +38,7 @@ ErrorOr<RequestOrResponseBlocking> should_response_to_request_be_blocked_due_to_
return RequestOrResponseBlocking::Allowed;
// 2. Let mimeType be the result of extracting a MIME type from response’s header list.
- auto mime_type = response.header_list()->extract_mime_type();
+ auto mime_type = TRY(response.header_list()->extract_mime_type());
// 3. Let destination be request’s destination.
auto const& destination = request.destination();