mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb: Remove OOM propagation from Fetch::Infrastructure::Requests
This commit is contained in:
parent
b3032befe0
commit
5a4f13dcd4
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/trflynn89
Commit: 5a4f13dcd4
Pull-request: https://github.com/SerenityOS/serenity/pull/24124
5 changed files with 24 additions and 28 deletions
|
@ -12,7 +12,7 @@
|
|||
namespace Web::Fetch::Fetching {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-cors-check
|
||||
ErrorOr<bool> cors_check(Infrastructure::Request const& request, Infrastructure::Response const& response)
|
||||
bool cors_check(Infrastructure::Request const& request, Infrastructure::Response const& response)
|
||||
{
|
||||
// 1. Let origin be the result of getting `Access-Control-Allow-Origin` from response’s header list.
|
||||
auto origin = response.header_list()->get("Access-Control-Allow-Origin"sv.bytes());
|
||||
|
@ -27,7 +27,7 @@ ErrorOr<bool> cors_check(Infrastructure::Request const& request, Infrastructure:
|
|||
return true;
|
||||
|
||||
// 4. If the result of byte-serializing a request origin with request is not origin, then return failure.
|
||||
if (TRY(request.byte_serialize_origin()) != *origin)
|
||||
if (request.byte_serialize_origin() != *origin)
|
||||
return false;
|
||||
|
||||
// 5. If request’s credentials mode is not "include", then return success.
|
||||
|
@ -46,7 +46,7 @@ ErrorOr<bool> cors_check(Infrastructure::Request const& request, Infrastructure:
|
|||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-tao-check
|
||||
ErrorOr<bool> tao_check(Infrastructure::Request const& request, Infrastructure::Response const& response)
|
||||
bool tao_check(Infrastructure::Request const& request, Infrastructure::Response const& response)
|
||||
{
|
||||
// 1. If request’s timing allow failed flag is set, then return failure.
|
||||
if (request.timing_allow_failed())
|
||||
|
@ -60,7 +60,7 @@ ErrorOr<bool> tao_check(Infrastructure::Request const& request, Infrastructure::
|
|||
return true;
|
||||
|
||||
// 4. If values contains the result of serializing a request origin with request, then return success.
|
||||
if (values.has_value() && values->contains_slow(TRY(request.serialize_origin())))
|
||||
if (values.has_value() && values->contains_slow(request.serialize_origin()))
|
||||
return true;
|
||||
|
||||
// 5. If request’s mode is "navigate" and request’s current URL’s origin is not same origin with request’s origin, then return failure.
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Web::Fetch::Fetching {
|
||||
|
||||
ErrorOr<bool> cors_check(Infrastructure::Request const&, Infrastructure::Response const&);
|
||||
ErrorOr<bool> tao_check(Infrastructure::Request const&, Infrastructure::Response const&);
|
||||
[[nodiscard]] bool cors_check(Infrastructure::Request const&, Infrastructure::Response const&);
|
||||
[[nodiscard]] bool tao_check(Infrastructure::Request const&, Infrastructure::Response const&);
|
||||
|
||||
}
|
||||
|
|
|
@ -994,13 +994,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
|
|||
// NOTE: As the CORS check is not to be applied to responses whose status is 304 or 407, or responses from
|
||||
// a service worker for that matter, it is applied here.
|
||||
if (request->response_tainting() == Infrastructure::Request::ResponseTainting::CORS
|
||||
&& !TRY_OR_IGNORE(cors_check(request, *response))) {
|
||||
&& !cors_check(request, *response)) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Request with 'cors' response tainting failed CORS check"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. If the TAO check for request and response returns failure, then set request’s timing allow failed flag.
|
||||
if (!TRY_OR_IGNORE(tao_check(request, *response)))
|
||||
if (!tao_check(request, *response))
|
||||
request->set_timing_allow_failed(true);
|
||||
}
|
||||
|
||||
|
@ -1353,7 +1353,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
|
|||
}
|
||||
|
||||
// 12. Append a request `Origin` header for httpRequest.
|
||||
TRY_OR_THROW_OOM(vm, http_request->add_origin_header());
|
||||
http_request->add_origin_header();
|
||||
|
||||
// FIXME: 13. Append the Fetch metadata headers for httpRequest.
|
||||
|
||||
|
@ -1876,7 +1876,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::
|
|||
|
||||
// 7. If a CORS check for request and response returns success and response’s status is an ok status, then:
|
||||
// NOTE: The CORS check is done on request rather than preflight to ensure the correct credentials mode is used.
|
||||
if (TRY_OR_IGNORE(cors_check(request, response)) && Infrastructure::is_ok_status(response->status())) {
|
||||
if (cors_check(request, response) && Infrastructure::is_ok_status(response->status())) {
|
||||
// 1. Let methods be the result of extracting header list values given `Access-Control-Allow-Methods` and response’s header list.
|
||||
auto methods_or_failure = Infrastructure::extract_header_list_values("Access-Control-Allow-Methods"sv.bytes(), response->header_list());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue