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

This commit is contained in:
Timothy Flynn 2024-04-26 13:26:55 -04:00 committed by Andreas Kling
commit b3032befe0
Notes: sideshowbarker 2024-07-16 22:26:05 +09:00
4 changed files with 5 additions and 5 deletions

View file

@ -36,10 +36,10 @@ bool is_forbidden_method(ReadonlyBytes method)
}
// https://fetch.spec.whatwg.org/#concept-method-normalize
ErrorOr<ByteBuffer> normalize_method(ReadonlyBytes method)
ByteBuffer normalize_method(ReadonlyBytes method)
{
// To normalize a method, if it is a byte-case-insensitive match for `DELETE`, `GET`, `HEAD`, `OPTIONS`, `POST`, or `PUT`, byte-uppercase it.
auto bytes = TRY(ByteBuffer::copy(method));
auto bytes = MUST(ByteBuffer::copy(method));
if (StringView { method }.is_one_of_ignoring_ascii_case("DELETE"sv, "GET"sv, "HEAD"sv, "OPTIONS"sv, "POST"sv, "PUT"sv))
Infra::byte_uppercase(bytes);
return bytes;

View file

@ -13,6 +13,6 @@ namespace Web::Fetch::Infrastructure {
[[nodiscard]] bool is_method(ReadonlyBytes);
[[nodiscard]] bool is_cors_safelisted_method(ReadonlyBytes);
[[nodiscard]] bool is_forbidden_method(ReadonlyBytes);
[[nodiscard]] ErrorOr<ByteBuffer> normalize_method(ReadonlyBytes);
[[nodiscard]] ByteBuffer normalize_method(ReadonlyBytes);
}

View file

@ -373,7 +373,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Method must not be one of CONNECT, TRACE, or TRACK"sv };
// 3. Normalize method.
method = TRY_OR_THROW_OOM(vm, String::from_utf8(TRY_OR_THROW_OOM(vm, Infrastructure::normalize_method(method.bytes()))));
method = TRY_OR_THROW_OOM(vm, String::from_utf8(Infrastructure::normalize_method(method.bytes())));
// 4. Set requests method to method.
request->set_method(MUST(ByteBuffer::copy(method.bytes())));

View file

@ -475,7 +475,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
return WebIDL::SecurityError::create(realm(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"_fly_string);
// 4. Normalize method.
auto normalized_method = TRY_OR_THROW_OOM(vm(), Fetch::Infrastructure::normalize_method(method));
auto normalized_method = Fetch::Infrastructure::normalize_method(method);
// 5. Let parsedURL be the result of parsing url with thiss relevant settings objects API base URL and thiss relevant settings objects API URL character encoding.
// FIXME: Pass in thiss relevant settings objects API URL character encoding.