diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 1550da1ac32..f71a2826594 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -138,6 +138,39 @@ WebIDL::ExceptionOr> fetch(JS: if (origin && *origin == Infrastructure::Request::Origin::Client) request.set_origin(request.client()->origin()); + // 11. If all of the following conditions are true: + if ( + // - request’s URL’s scheme is an HTTP(S) scheme + Infrastructure::is_http_or_https_scheme(request.url().scheme()) + // - request’s mode is "same-origin", "cors", or "no-cors" + && (request.mode() == Infrastructure::Request::Mode::SameOrigin || request.mode() == Infrastructure::Request::Mode::CORS || request.mode() == Infrastructure::Request::Mode::NoCORS) + // - request’s window is an environment settings object + && request.window().has>() + // - request’s method is `GET` + && StringView { request.method() }.equals_ignoring_ascii_case("GET"sv) + // - request’s unsafe-request flag is not set or request’s header list is empty + && (!request.unsafe_request() || request.header_list()->is_empty())) { + // 1. Assert: request’s origin is same origin with request’s client’s origin. + VERIFY(request.origin().has() && request.origin().get().is_same_origin(request.client()->origin())); + + // 2. Let onPreloadedResponseAvailable be an algorithm that runs the following step given a response + // response: set fetchParams’s preloaded response candidate to response. + auto on_preloaded_response_available = JS::create_heap_function(realm.heap(), [fetch_params](JS::NonnullGCPtr response) { + fetch_params->set_preloaded_response_candidate(response); + }); + + // FIXME: 3. Let foundPreloadedResource be the result of invoking consume a preloaded resource for request’s + // window, given request’s URL, request’s destination, request’s mode, request’s credentials mode, + // request’s integrity metadata, and onPreloadedResponseAvailable. + auto found_preloaded_resource = false; + (void)on_preloaded_response_available; + + // 4. If foundPreloadedResource is true and fetchParams’s preloaded response candidate is null, then set + // fetchParams’s preloaded response candidate to "pending". + if (found_preloaded_resource && fetch_params->preloaded_response_candidate().has()) + fetch_params->set_preloaded_response_candidate(Infrastructure::FetchParams::PreloadedResponseCandidatePendingTag {}); + } + // 12. If request’s policy container is "client", then: auto const* policy_container = request.policy_container().get_pointer(); if (policy_container) {