LibWeb: Remove OOM propagation from Fetch::Infrastructure::Requests

This commit is contained in:
Timothy Flynn 2024-04-26 13:35:10 -04:00 committed by Andreas Kling
commit 5a4f13dcd4
Notes: sideshowbarker 2024-07-17 02:28:18 +09:00
5 changed files with 24 additions and 28 deletions

View file

@ -186,21 +186,21 @@ bool Request::has_redirect_tainted_origin() const
}
// https://fetch.spec.whatwg.org/#serializing-a-request-origin
ErrorOr<String> Request::serialize_origin() const
String Request::serialize_origin() const
{
// 1. If request has a redirect-tainted origin, then return "null".
if (has_redirect_tainted_origin())
return "null"_string;
// 2. Return requests origin, serialized.
return String::from_byte_string(m_origin.get<HTML::Origin>().serialize());
return MUST(String::from_byte_string(m_origin.get<HTML::Origin>().serialize()));
}
// https://fetch.spec.whatwg.org/#byte-serializing-a-request-origin
ErrorOr<ByteBuffer> Request::byte_serialize_origin() const
ByteBuffer Request::byte_serialize_origin() const
{
// Byte-serializing a request origin, given a request request, is to return the result of serializing a request origin with request, isomorphic encoded.
return ByteBuffer::copy(TRY(serialize_origin()).bytes());
return MUST(ByteBuffer::copy(serialize_origin().bytes()));
}
// https://fetch.spec.whatwg.org/#concept-request-clone
@ -259,7 +259,7 @@ JS::NonnullGCPtr<Request> Request::clone(JS::Realm& realm) const
}
// https://fetch.spec.whatwg.org/#concept-request-add-range-header
ErrorOr<void> Request::add_range_header(u64 first, Optional<u64> const& last)
void Request::add_range_header(u64 first, Optional<u64> const& last)
{
// To add a range header to a request request, with an integer first, and an optional integer last, run these steps:
@ -270,14 +270,14 @@ ErrorOr<void> Request::add_range_header(u64 first, Optional<u64> const& last)
auto range_value = MUST(ByteBuffer::copy("bytes"sv.bytes()));
// 3. Serialize and isomorphic encode first, and append the result to rangeValue.
TRY(range_value.try_append(TRY(String::number(first)).bytes()));
range_value.append(MUST(String::number(first)).bytes());
// 4. Append 0x2D (-) to rangeValue.
TRY(range_value.try_append('-'));
range_value.append('-');
// 5. If last is given, then serialize and isomorphic encode it, and append the result to rangeValue.
if (last.has_value())
TRY(range_value.try_append(TRY(String::number(*last)).bytes()));
range_value.append(MUST(String::number(*last)).bytes());
// 6. Append (`Range`, rangeValue) to requests header list.
auto header = Header {
@ -285,15 +285,13 @@ ErrorOr<void> Request::add_range_header(u64 first, Optional<u64> const& last)
.value = move(range_value),
};
m_header_list->append(move(header));
return {};
}
// https://fetch.spec.whatwg.org/#append-a-request-origin-header
ErrorOr<void> Request::add_origin_header()
void Request::add_origin_header()
{
// 1. Let serializedOrigin be the result of byte-serializing a request origin with request.
auto serialized_origin = TRY(byte_serialize_origin());
auto serialized_origin = byte_serialize_origin();
// 2. If requests response tainting is "cors" or requests mode is "websocket", then append (`Origin`, serializedOrigin) to requests header list.
if (m_response_tainting == ResponseTainting::CORS || m_mode == Mode::WebSocket) {
@ -345,8 +343,6 @@ ErrorOr<void> Request::add_origin_header()
};
m_header_list->append(move(header));
}
return {};
}
// https://fetch.spec.whatwg.org/#cross-origin-embedder-policy-allows-credentials