LibWeb: Align Fetching chapter's "To fetch" with latest spec changes

This commit is contained in:
Kenneth Myhra 2025-08-07 11:41:58 +02:00 committed by Sam Atkins
commit 1b350596fb
Notes: github-actions[bot] 2025-08-08 10:14:03 +00:00

View file

@ -84,7 +84,6 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'fetch' with: request @ {}", &request);
auto& vm = realm.vm();
auto& heap = vm.heap();
// 1. Assert: requests mode is "navigate" or processEarlyHintsResponse is null.
VERIFY(request.mode() == Infrastructure::Request::Mode::Navigate || !algorithms.process_early_hints_response());
@ -95,7 +94,10 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
// 3. Let crossOriginIsolatedCapability be false.
auto cross_origin_isolated_capability = HTML::CanUseCrossOriginIsolatedAPIs::No;
// 4. If requests client is non-null, then:
// 4. Populate request from client given request.
populate_request_from_client(realm, request);
// 5. If requests client is non-null, then:
if (request.client() != nullptr) {
// 1. Set taskDestination to requests clients global object.
task_destination = GC::Ref { request.client()->global_object() };
@ -104,11 +106,11 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
cross_origin_isolated_capability = request.client()->cross_origin_isolated_capability();
}
// 5. If useParallelQueue is true, then set taskDestination to the result of starting a new parallel queue.
// 6. If useParallelQueue is true, then set taskDestination to the result of starting a new parallel queue.
if (use_parallel_queue == UseParallelQueue::Yes)
task_destination = HTML::ParallelQueue::create();
// 6. Let timingInfo be a new fetch timing info whose start time and post-redirect start time are the coarsened
// 7. Let timingInfo be a new fetch timing info whose start time and post-redirect start time are the coarsened
// shared current time given crossOriginIsolatedCapability, and render-blocking is set to requests
// render-blocking.
auto timing_info = Infrastructure::FetchTimingInfo::create(vm);
@ -117,7 +119,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
timing_info->set_post_redirect_start_time(now);
timing_info->set_render_blocking(request.render_blocking());
// 7. Let fetchParams be a new fetch params whose request is request, timing info is timingInfo, process request
// 8. Let fetchParams be a new fetch params whose request is request, timing info is timingInfo, process request
// body chunk length is processRequestBodyChunkLength, process request end-of-body is processRequestEndOfBody,
// process early hints response is processEarlyHintsResponse, process response is processResponse, process
// response consume body is processResponseConsumeBody, process response end-of-body is processResponseEndOfBody,
@ -127,34 +129,18 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
fetch_params->set_task_destination(task_destination);
fetch_params->set_cross_origin_isolated_capability(cross_origin_isolated_capability);
// 8. If requests body is a byte sequence, then set requests body to requests body as a body.
// 9. If requests body is a byte sequence, then set requests body to requests body as a body.
if (auto const* buffer = request.body().get_pointer<ByteBuffer>())
request.set_body(Infrastructure::byte_sequence_as_body(realm, buffer->bytes()));
// 9. If requests window is "client", then set requests window to requests client, if requests clients global
// object is a Window object; otherwise "no-window".
auto const* window = request.traversable_for_user_prompts().get_pointer<Infrastructure::Request::TraversableForUserPrompts>();
if (window && *window == Infrastructure::Request::TraversableForUserPrompts::Client) {
if (is<HTML::Window>(request.client()->global_object())) {
request.set_traversable_for_user_prompts(request.client());
} else {
request.set_traversable_for_user_prompts(Infrastructure::Request::TraversableForUserPrompts::NoTraversable);
}
}
// 10. If requests origin is "client", then set requests origin to requests clients origin.
auto const* origin = request.origin().get_pointer<Infrastructure::Request::Origin>();
if (origin && *origin == Infrastructure::Request::Origin::Client)
request.set_origin(request.client()->origin());
// 11. If all of the following conditions are true:
// 10. If all of the following conditions are true:
if (
// - requests URLs scheme is an HTTP(S) scheme
Infrastructure::is_http_or_https_scheme(request.url().scheme())
// - requests 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)
// - requests window is an environment settings object
&& request.traversable_for_user_prompts().has<GC::Ptr<HTML::EnvironmentSettingsObject>>()
// - requests client is not null, and requests clients global object is a Window object
&& request.client() && is<HTML::Window>(request.client()->global_object())
// - requests method is `GET`
&& StringView { request.method() }.equals_ignoring_ascii_case("GET"sv)
// - requests unsafe-request flag is not set or requests header list is empty
@ -180,20 +166,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
fetch_params->set_preloaded_response_candidate(Infrastructure::FetchParams::PreloadedResponseCandidatePendingTag {});
}
// 12. If requests policy container is "client", then:
auto const* policy_container = request.policy_container().get_pointer<Infrastructure::Request::PolicyContainer>();
if (policy_container) {
VERIFY(*policy_container == Infrastructure::Request::PolicyContainer::Client);
// 1. If requests client is non-null, then set requests policy container to a clone of requests clients
// policy container.
if (request.client() != nullptr)
request.set_policy_container(request.client()->policy_container()->clone(heap));
// 2. Otherwise, set requests policy container to a new policy container.
else
request.set_policy_container(heap.allocate<HTML::PolicyContainer>(heap));
}
// 13. If requests header list does not contain `Accept`, then:
// 11. If requests header list does not contain `Accept`, then:
if (!request.header_list()->contains("Accept"sv.bytes())) {
// 1. Let value be `*/*`.
auto value = "*/*"sv;
@ -240,7 +213,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
request.header_list()->append(move(header));
}
// 14. If requests header list does not contain `Accept-Language`, then user agents should append
// 12. If requests header list does not contain `Accept-Language`, then user agents should append
// (`Accept-Language, an appropriate header value) to requests header list.
if (!request.header_list()->contains("Accept-Language"sv.bytes())) {
StringBuilder accept_language;
@ -250,24 +223,25 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
request.header_list()->append(move(header));
}
// 15. If requests priority is null, then use requests initiator, destination, and render-blocking appropriately
// in setting requests priority to a user-agent-defined object.
// 13. If requests internal priority is null, then use requests priority, initiator, destination, and
// render-blocking in an implementation-defined manner to set requests internal priority to an
// implementation-defined object.
// NOTE: The user-agent-defined object could encompass stream weight and dependency for HTTP/2, and equivalent
// information used to prioritize dispatch and processing of HTTP/1 fetches.
// 16. If request is a subresource request, then:
// 14. If request is a subresource request, then:
if (request.is_subresource_request()) {
// 1. Let record be a new fetch record whose request is request and controller is fetchParamss controller.
auto record = Infrastructure::FetchRecord::create(vm, request, fetch_params->controller());
// 2. Append record to requests clients fetch group list of fetch records.
// 2. Append record to requests clients fetch groups fetch records.
request.client()->fetch_group().append(record);
}
// 17. Run main fetch given fetchParams.
// 15. Run main fetch given fetchParams.
(void)TRY(main_fetch(realm, fetch_params));
// 18. Return fetchParamss controller.
// 16. Return fetchParamss controller.
return fetch_params->controller();
}