Truly independent web browser
LibWeb: Record each fetch's body intent on FetchAlgorithms
Luke Wilde0a579ab8ede7
diff --git a/Libraries/LibWeb/CSS/Fetch.cpp b/Libraries/LibWeb/CSS/Fetch.cppindex b5f4ca536b0..c4a0d78322a 100644--- a/Libraries/LibWeb/CSS/Fetch.cpp+++ b/Libraries/LibWeb/CSS/Fetch.cpp@@ -140,7 +140,7 @@ GC::Ptr<Fetch::Infrastructure::FetchController> fetch_a_style_resource(StyleResoauto& environment_settings = *css_rule_or_declaration.environment_settings_object;- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = move(process_response);return Fetch::Fetching::fetch(environment_settings.realm(), *request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)));diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cppindex 86ba2f654db..c7dc5195c9c 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/Violation.cpp@@ -508,7 +508,7 @@ void Violation::report_a_violation(JS::Realm& realm)request->set_redirect_mode(Fetch::Infrastructure::Request::RedirectMode::Error);// 4. Fetch request. The result will be ignored.- (void)Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create({}));+ (void)Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create(Fetch::Infrastructure::FetchAlgorithms::Input { Fetch::Engine::BodyIntent::DrainAndDiscard }));}}}diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 9c8f33d6555..a0bfc3058d5 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -779,7 +779,7 @@ void Element::download_the_hyperlink(Optional<Utf16String> hyperlink_suffix, HTM// 3. Let response be the result of fetching request.// 4. Handle as a download response with subject's node navigable and null.auto controller_holder = Fetch::Infrastructure::FetchControllerHolder::create();- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response = [navigable = GC::Ref { *navigable }, url, proposed_filename = move(proposed_filename), interface_origin = document().origin(), controller_holder](GC::Ref<Fetch::Infrastructure::Response> response) {if (response->is_network_error())return;diff --git a/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Libraries/LibWeb/Fetch/FetchMethod.cppindex e771c14bc43..660ffa1bfcb 100644--- a/Libraries/LibWeb/Fetch/FetchMethod.cpp+++ b/Libraries/LibWeb/Fetch/FetchMethod.cpp@@ -161,18 +161,9 @@ GC::Ref<WebIDL::Promise> fetch(JS::Realm& realm, RequestInfo const& input, BindiGC::Ref { *response_object_holder->response_object });WebIDL::resolve_promise(relevant_realm, promise_capability, response_value);};- controller_holder->set_controller(Fetching::fetch(- realm,- request,- Infrastructure::FetchAlgorithms::create(- {- .process_request_body_chunk_length = {},- .process_request_end_of_body = {},- .process_early_hints_response = {},- .process_response = move(process_response),- .process_response_end_of_body = {},- .process_response_consume_body = {},- })));+ Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Engine::BodyIntent::DeliverStreamToConsumerAgent };+ fetch_algorithms_input.process_response = move(process_response);+ controller_holder->set_controller(Fetching::fetch(realm, request, Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input))));// 11. Add the following abort steps to requestObject’s signal:(void)request_object->signal()->add_abort_algorithm([locally_aborted, request, controller_holder, promise_capability, request_object, response_object_holder, &relevant_realm] {diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 4942e41c733..81b2deee857 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -240,8 +240,7 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:// process early hints response is processEarlyHintsResponse, process response is processResponse, process// response consume body is processResponseConsumeBody, process response end-of-body is processResponseEndOfBody,// task destination is taskDestination, and cross-origin isolated capability is crossOriginIsolatedCapability.- auto fetch_params = Infrastructure::FetchParams::create(request, timing_info);- fetch_params->set_algorithms(algorithms);+ auto fetch_params = Infrastructure::FetchParams::create(request, algorithms, timing_info);fetch_params->set_task_destination(task_destination);fetch_params->set_cross_origin_isolated_capability(cross_origin_isolated_capability);fetch_params->set_has_response_body_transfer_lease(create_response_body_transfer_lease == CreateResponseBodyTransferLease::Yes);@@ -2654,7 +2653,7 @@ GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm& realm, Infrastructure::// 6. Let response be the result of running HTTP-network-or-cache fetch given a new fetch params whose request is preflight.// FIXME: The spec doesn't say anything about timing_info here, but FetchParams requires a non-null FetchTimingInfo object.auto timing_info = Infrastructure::FetchTimingInfo::create();- auto fetch_params = Infrastructure::FetchParams::create(preflight, timing_info);+ auto fetch_params = Infrastructure::FetchParams::create(preflight, Infrastructure::FetchAlgorithms::create(Infrastructure::FetchAlgorithms::Input { Engine::BodyIntent::DrainAndDiscard }), timing_info);auto returned_pending_response = PendingResponse::create(request);diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cppindex f75c95f555a..94b4c83be03 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp@@ -21,6 +21,7 @@ GC::Ref<FetchAlgorithms> FetchAlgorithms::create(Input input)auto process_response_end_of_body = GC::create_function(GC::Heap::the(), move(input.process_response_end_of_body));auto process_response_consume_body = GC::create_function(GC::Heap::the(), move(input.process_response_consume_body));return GC::Heap::the().allocate<FetchAlgorithms>(+ input.body_intent,process_request_body_chunk_length,process_request_end_of_body,process_early_hints_response,@@ -29,19 +30,16 @@ GC::Ref<FetchAlgorithms> FetchAlgorithms::create(Input input)process_response_consume_body);}-GC::Ref<FetchAlgorithms> FetchAlgorithms::create(JS::VM&, Input input)-{- return create(move(input));-}-FetchAlgorithms::FetchAlgorithms(+ Engine::BodyIntent body_intent,ProcessRequestBodyChunkLengthHeapFunction process_request_body_chunk_length,ProcessRequestEndOfBodyHeapFunction process_request_end_of_body,ProcessEarlyHintsResponseHeapFunction process_early_hints_response,ProcessResponseHeapFunction process_response,ProcessResponseEndOfBodyHeapFunction process_response_end_of_body,ProcessResponseConsumeBodyHeapFunction process_response_consume_body)- : m_process_request_body_chunk_length(process_request_body_chunk_length)+ : m_body_intent(body_intent)+ , m_process_request_body_chunk_length(process_request_body_chunk_length), m_process_request_end_of_body(process_request_end_of_body), m_process_early_hints_response(process_early_hints_response), m_process_response(process_response)diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.hindex 9236c36f88f..d4dcf5e2113 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h@@ -12,6 +12,7 @@#include <LibGC/Ptr.h>#include <LibJS/Heap/Cell.h>#include <LibWeb/Export.h>+#include <LibWeb/Fetch/Engine/BodyIntent.h>#include <LibWeb/Forward.h>namespace Web::Fetch::Infrastructure {@@ -40,6 +41,12 @@ public:using ProcessResponseConsumeBodyHeapFunction = GC::Ref<GC::Function<ProcessResponseConsumeBodyFunction::FunctionType>>;struct Input {+ explicit Input(Engine::BodyIntent body_intent)+ : body_intent(body_intent)+ {+ }++ Engine::BodyIntent body_intent;ProcessRequestBodyChunkLengthFunction process_request_body_chunk_length;ProcessRequestEndOfBodyFunction process_request_end_of_body;ProcessEarlyHintsResponseFunction process_early_hints_response;@@ -49,8 +56,8 @@ public:};[[nodiscard]] static GC::Ref<FetchAlgorithms> create(Input);- [[nodiscard]] static GC::Ref<FetchAlgorithms> create(JS::VM&, Input);+ Engine::BodyIntent body_intent() const { return m_body_intent; }ProcessRequestBodyChunkLengthFunction const& process_request_body_chunk_length() const { return m_process_request_body_chunk_length->function(); }ProcessRequestEndOfBodyFunction const& process_request_end_of_body() const { return m_process_request_end_of_body->function(); }ProcessEarlyHintsResponseFunction const& process_early_hints_response() const { return m_process_early_hints_response->function(); }@@ -61,7 +68,8 @@ public:virtual void visit_edges(JS::Cell::Visitor&) override;private:- explicit FetchAlgorithms(+ FetchAlgorithms(+ Engine::BodyIntent,ProcessRequestBodyChunkLengthHeapFunction process_request_body_chunk_length,ProcessRequestEndOfBodyHeapFunction process_request_end_of_body,ProcessEarlyHintsResponseHeapFunction process_early_hints_response,@@ -69,6 +77,7 @@ private:ProcessResponseEndOfBodyHeapFunction process_response_end_of_body,ProcessResponseConsumeBodyHeapFunction process_response_consume_body);+ Engine::BodyIntent m_body_intent;ProcessRequestBodyChunkLengthHeapFunction m_process_request_body_chunk_length;ProcessRequestEndOfBodyHeapFunction m_process_request_end_of_body;ProcessEarlyHintsResponseHeapFunction m_process_early_hints_response;diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cppindex f4d3863d968..74f7fe03392 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp@@ -164,7 +164,8 @@ void FetchController::stop_fetch()});if (m_fetch_params) {- auto fetch_algorithms = FetchAlgorithms::create({});+ // NB: Nobody reads a stopped fetch's body.+ auto fetch_algorithms = FetchAlgorithms::create(FetchAlgorithms::Input { Engine::BodyIntent::DrainAndDiscard });m_fetch_params->set_algorithms(fetch_algorithms);}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cppindex ad942351a74..be358ef0d54 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp@@ -13,7 +13,7 @@ namespace Web::Fetch::Infrastructure {GC_DEFINE_ALLOCATOR(FetchParams);-FetchParams::FetchParams(GC::Ref<Request> request, GC::Ref<FetchAlgorithms> algorithms, GC::Ref<FetchController> controller, NonnullRefPtr<FetchTimingInfo> timing_info)+FetchParams::FetchParams(GC::Ref<Request> request, GC::Ref<FetchAlgorithms const> algorithms, GC::Ref<FetchController> controller, NonnullRefPtr<FetchTimingInfo> timing_info): m_request(request), m_algorithms(algorithms), m_controller(controller)@@ -34,9 +34,8 @@ FetchParams::FetchParams(FetchParams const& params){}-GC::Ref<FetchParams> FetchParams::create(GC::Ref<Request> request, NonnullRefPtr<FetchTimingInfo> timing_info)+GC::Ref<FetchParams> FetchParams::create(GC::Ref<Request> request, GC::Ref<FetchAlgorithms const> algorithms, NonnullRefPtr<FetchTimingInfo> timing_info){- auto algorithms = Infrastructure::FetchAlgorithms::create({});auto controller = Infrastructure::FetchController::create();return GC::Heap::the().allocate<FetchParams>(request, algorithms, controller, move(timing_info));}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.hindex 5798b97ba23..614a8970031 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h@@ -28,7 +28,7 @@ public:struct PreloadedResponseCandidatePendingTag { };using PreloadedResponseCandidate = Variant<Empty, PreloadedResponseCandidatePendingTag, GC::Ref<Response>>;- [[nodiscard]] static GC::Ref<FetchParams> create(GC::Ref<Request>, NonnullRefPtr<FetchTimingInfo>);+ [[nodiscard]] static GC::Ref<FetchParams> create(GC::Ref<Request>, GC::Ref<FetchAlgorithms const>, NonnullRefPtr<FetchTimingInfo>);[[nodiscard]] static GC::Ref<FetchParams> copy(FetchParams const&);[[nodiscard]] GC::Ref<Request> request() const { return m_request; }@@ -60,7 +60,7 @@ public:void set_has_response_body_transfer_lease(bool value) { m_has_response_body_transfer_lease = value; }private:- FetchParams(GC::Ref<Request>, GC::Ref<FetchAlgorithms>, GC::Ref<FetchController>, NonnullRefPtr<FetchTimingInfo>);+ FetchParams(GC::Ref<Request>, GC::Ref<FetchAlgorithms const>, GC::Ref<FetchController>, NonnullRefPtr<FetchTimingInfo>);FetchParams(FetchParams const&);virtual void visit_edges(JS::Cell::Visitor&) override;diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cppindex c9181d31a7c..964e48950a3 100644--- a/Libraries/LibWeb/HTML/EventSource.cpp+++ b/Libraries/LibWeb/HTML/EventSource.cpp@@ -122,7 +122,7 @@ WebIDL::ExceptionOr<GC::Ref<EventSource>> EventSource::create(WindowOrWorkerGlob// 15. Fetch request, with processResponseEndOfBody set to processEventSourceEndOfBody and processResponse set to the// following steps given response res:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response_end_of_body = move(process_event_source_end_of_body);fetch_algorithms_input.process_response = [event_source](GC::Ref<Fetch::Infrastructure::Response> response) {diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex 1a64afdbac8..87469f0a183 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -537,7 +537,7 @@ void HTMLLinkElement::default_fetch_and_process_linked_resource(u64 fetch_genera}// 7. Fetch request with processResponseConsumeBody set to the following steps given response response and null, failure, or a byte sequence bodyBytes:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [this, fetch_generation](auto response, auto body_bytes) {// "if, since the resource in question was fetched, it has become appropriate to fetch it again"if (fetch_generation != m_current_fetch_generation)@@ -809,7 +809,7 @@ void HTMLLinkElement::fetch_and_process_linked_prefetch_resource()// 6. Let processPrefetchResponse be the following steps given a response response and null, failure, or a byte// sequence bytesOrNull:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [this, fetch_generation = m_current_fetch_generation](auto response, auto) {if (fetch_generation != m_current_fetch_generation)return;@@ -1023,7 +1023,7 @@ void HTMLLinkElement::preload(LinkProcessingOptions& options, Function<void(Fetc// 11. Set controller to the result of fetching request, with processResponseConsumeBody set to the following steps// given a response response and null, failure, or a byte sequence bodyBytes:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [&realm, options = GC::Ref { options }, process_response = move(process_response), entry, report_timing](GC::Ref<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {// FIXME: If the response is CORS cross-origin, we must use its internal response to query any of its data. See:// https://github.com/whatwg/html/issues/9355@@ -1659,7 +1659,7 @@ void HTMLLinkElement::load_fallback_favicon_if_needed(GC::Ref<DOM::Document> docrequest->set_use_url_credentials(true);// 2. Let response be the result of fetching request.- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response = [document, request](GC::Ref<Fetch::Infrastructure::Response> response) {auto& realm = document->relevant_settings_object().realm();auto global = GC::Ref { realm.global_object() };diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex ef7afff41ad..536058a07a4 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -1663,7 +1663,7 @@ void HTMLMediaElement::run_remote_mode_resource_fetch_steps(ByteRange byte_range}// 8. Fetch request, with processResponse set to the following steps given response response:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response = [self = GC::Ref(*this), byte_range = move(byte_range), fetch_generation](auto response) mutable {auto& fetch_data = self->m_remote_fetch_data;diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex 7eb122a413e..6c2be912142 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -280,7 +280,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Object);request->set_use_url_credentials(true);- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response = [this](GC::Ref<Fetch::Infrastructure::Response> response) {auto& realm = HTML::relevant_realm(*this);auto& global = document().relevant_settings_object().realm().global_object();diff --git a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp b/Libraries/LibWeb/HTML/HTMLTrackElement.cppindex 86c7a6f112d..8238cbcfa27 100644--- a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLTrackElement.cpp@@ -274,7 +274,7 @@ void HTMLTrackElement::start_the_track_processing_model_parallel_steps()// 3. Set request's initiator type to "track".request->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Track);- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [this, src_generation = m_src_generation](auto response, auto body_bytes) {m_loading = false;diff --git a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Libraries/LibWeb/HTML/HTMLVideoElement.cppindex f3f025644b6..46320fca2c7 100644--- a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLVideoElement.cpp@@ -296,7 +296,7 @@ WebIDL::ExceptionOr<void> HTMLVideoElement::determine_element_poster_frame(Optiorequest->set_use_url_credentials(true);// 6. Fetch request. This must delay the load event of the element's node document.- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };m_load_event_delayer.emplace(document());// 7. If an image is thus obtained, the poster frame is that image. Otherwise, there is no poster frame.diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 3d2b9dd3a33..fafa6ac2733 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -2274,18 +2274,12 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigationstate_holder->continuation_steps->function()(NavigationParamsFetchStateHolder::ContinuationReason::GotResponse);};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };+ fetch_algorithms_input.process_response = move(process_response);state_holder->fetch_controller = Fetch::Fetching::fetch(realm,state_holder->request,- Fetch::Infrastructure::FetchAlgorithms::create(realm.vm(),- {- .process_request_body_chunk_length = {},- .process_request_end_of_body = {},- .process_early_hints_response = {},- .process_response = move(process_response),- .process_response_end_of_body = {},- .process_response_consume_body = {},- }),+ Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)),Fetch::Fetching::UseParallelQueue::Yes,Fetch::Fetching::CreateResponseBodyTransferLease::Yes);}diff --git a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp b/Libraries/LibWeb/HTML/NavigatorBeacon.cppindex 840f16b1670..6ece6508e74 100644--- a/Libraries/LibWeb/HTML/NavigatorBeacon.cpp+++ b/Libraries/LibWeb/HTML/NavigatorBeacon.cpp@@ -85,7 +85,7 @@ WebIDL::ExceptionOr<bool> NavigatorBeaconPartial::send_beacon(Utf16View url, Fetreq->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Beacon); // initiator type: "beacon"// 7.2 Fetch req.- (void)Fetch::Fetching::fetch(realm, req, Fetch::Infrastructure::FetchAlgorithms::create({}));+ (void)Fetch::Fetching::fetch(realm, req, Fetch::Infrastructure::FetchAlgorithms::create(Fetch::Infrastructure::FetchAlgorithms::Input { Fetch::Engine::BodyIntent::DrainAndDiscard }));return true;}diff --git a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cppindex d2d2b0d06f9..fe591bd8560 100644--- a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp+++ b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp@@ -144,7 +144,7 @@ void issue_speculative_fetch(JS::Realm& realm, DOM::Document& document, URL::URL// the same resource again. A response the HTTP cache can't store would be fetched twice, so once the// speculative fetch succeeds, offer its response to the normal parser's fetch the way a preload is, through// the document's map of preloaded resources. That fetch still runs main fetch's checks before using it.- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [&realm, document = GC::Ref { document }, parser = GC::Weak { document.active_parser() }, request](GC::Ref<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {auto* byte_sequence = body_bytes.get_pointer<Core::ImmutableBytes>();if (response->is_network_error() || !byte_sequence)@@ -236,7 +236,7 @@ void issue_speculative_module_fetch(DOM::Document& document, URL::URL const& urlrequest->set_initiator_type(Fetch::Infrastructure::Request::InitiatorType::Script);set_up_module_script_request(request, options);- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DrainAndDiscard };auto algorithms = Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input));(void)Fetch::Fetching::fetch(settings_object.realm(), request, algorithms);}diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cppindex 55bb2ba70ac..7430189d055 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp@@ -660,7 +660,7 @@ void fetch_classic_script(GC::Ref<HTMLScriptElement> element, URL::URL const& ur// 5. Fetch request with the following processResponseConsumeBody steps given response response and null, failure,// or a byte sequence bodyBytes:- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = [request, &settings_object, options = move(options), character_encoding = move(character_encoding), on_complete = move(on_complete)](auto response, auto body_bytes) {// 1. Set response to response's unsafe response.response = response->unsafe_response();@@ -876,7 +876,7 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, Envir// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.else {- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = move(process_response_consume_body);Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)));}@@ -918,7 +918,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri}// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.else {- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = move(process_response_consume_body);Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)));}@@ -1290,7 +1290,7 @@ void fetch_single_module_script(JS::Realm& realm,if (result.is_exception())module_map.complete_fetch(url, module_type, nullptr);} else {- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = move(process_response_consume_body);Fetch::Fetching::fetch(realm, request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)));}diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cppindex 565258fa419..32e85c631b4 100644--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp@@ -140,7 +140,7 @@ void SharedResourceRequest::fetch_resource(GC::Ref<Fetch::Infrastructure::Reques}GC::Weak weak_this { *this };- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };fetch_algorithms_input.process_response = [weak_this, &realm, request](GC::Ref<Fetch::Infrastructure::Response> response) {auto self = weak_this.ptr();if (!self)diff --git a/Libraries/LibWeb/SVG/SVGScriptElement.cpp b/Libraries/LibWeb/SVG/SVGScriptElement.cppindex af070c7ae32..685e7f9dd43 100644--- a/Libraries/LibWeb/SVG/SVGScriptElement.cpp+++ b/Libraries/LibWeb/SVG/SVGScriptElement.cpp@@ -131,7 +131,7 @@ void SVGScriptElement::process_the_script_element()if (m_parser_inserted)m_document->set_pending_parsing_blocking_svg_script(this);- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body= [self = GC::Ref { *this }, script_url](auto response, auto body_bytes) {if (response->is_network_error()) {diff --git a/Libraries/LibWeb/ServiceWorker/Cache.cpp b/Libraries/LibWeb/ServiceWorker/Cache.cppindex 2862b858008..29b95f59095 100644--- a/Libraries/LibWeb/ServiceWorker/Cache.cpp+++ b/Libraries/LibWeb/ServiceWorker/Cache.cpp@@ -286,7 +286,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,// 6. Run the following substeps in parallel:Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [&realm, fetch_controllers, inner_request, response_promise]() {// * Append the result of fetching r.- Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };// * To processResponse for response, run these substeps:fetch_algorithms_input.process_response = [&realm, fetch_controllers, response_promise](GC::Ref<Fetch::Infrastructure::Response> response) {diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cppindex 6398434c749..05b8782e0f2 100644--- a/Libraries/LibWeb/ServiceWorker/Job.cpp+++ b/Libraries/LibWeb/ServiceWorker/Job.cpp@@ -237,7 +237,7 @@ static void update(JS::VM& vm, GC::Ref<Job> job)// 3. Set request’s service-workers mode to "none".request->set_service_workers_mode(Fetch::Infrastructure::Request::ServiceWorkersMode::None);- Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Web::Fetch::Engine::BodyIntent::ConsumeForCallback };fetch_algorithms_input.process_response_consume_body = move(process_custom_fetch_response);// 4. If the isTopLevel flag is unset, then return the result of fetching request.diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cppindex 735773edad7..89fd3031731 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp@@ -1016,18 +1016,11 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB};// 10. Set this’s fetch controller to the result of fetching req with processRequestBodyChunkLength set to processRequestBodyChunkLength, processRequestEndOfBody set to processRequestEndOfBody, and processResponse set to processResponse.- m_fetch_controller = Fetch::Fetching::fetch(- associated_realm,- request,- Fetch::Infrastructure::FetchAlgorithms::create(- {- .process_request_body_chunk_length = move(process_request_body_chunk_length),- .process_request_end_of_body = move(process_request_end_of_body),- .process_early_hints_response = {},- .process_response = move(process_response),- .process_response_end_of_body = {},- .process_response_consume_body = {},- }));+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };+ fetch_algorithms_input.process_request_body_chunk_length = move(process_request_body_chunk_length);+ fetch_algorithms_input.process_request_end_of_body = move(process_request_end_of_body);+ fetch_algorithms_input.process_response = move(process_response);+ m_fetch_controller = Fetch::Fetching::fetch(associated_realm, request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)));// AD-HOC: Stopping the fetch, as aborting the document does, discards it without a response. Hand this an// aborted network error instead, so that it fires abort as for a canceled fetch.@@ -1087,19 +1080,9 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB};// 3. Set this’s fetch controller to the result of fetching req with processResponseConsumeBody set to processResponseConsumeBody and useParallelQueue set to true.- m_fetch_controller = Fetch::Fetching::fetch(- associated_realm,- request,- Fetch::Infrastructure::FetchAlgorithms::create(- {- .process_request_body_chunk_length = {},- .process_request_end_of_body = {},- .process_early_hints_response = {},- .process_response = {},- .process_response_end_of_body = {},- .process_response_consume_body = move(process_response_consume_body),- }),- Fetch::Fetching::UseParallelQueue::Yes);+ Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::SyncAccumulate };+ fetch_algorithms_input.process_response_consume_body = move(process_response_consume_body);+ m_fetch_controller = Fetch::Fetching::fetch(associated_realm, request, Fetch::Infrastructure::FetchAlgorithms::create(move(fetch_algorithms_input)), Fetch::Fetching::UseParallelQueue::Yes);// 4. Let now be the present time.// 5. Pause until either processedResponse is true or this’s timeout is not 0 and this’s timeout milliseconds have passed since now.diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cppindex 7da922d0ea3..f508bf9d6c9 100644--- a/Services/WebWorker/WorkerHost.cpp+++ b/Services/WebWorker/WorkerHost.cpp@@ -163,7 +163,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mesauto perform_fetch_function = [inside_settings, outside_settings, worker_global_scope, is_shared](GC::Ref<Web::Fetch::Infrastructure::Request> request, Web::HTML::TopLevelModule is_top_level, Web::Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction process_custom_fetch_response) -> Web::WebIDL::ExceptionOr<void> {auto& realm = inside_settings->realm();- Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input {};+ Web::Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Web::Fetch::Engine::BodyIntent::ConsumeForCallback };// 1. If isTopLevel is false, fetch request with processResponseConsumeBody set to processCustomFetchResponse,// and abort these steps.diff --git a/Tests/LibWeb/TestFetchResponse.cpp b/Tests/LibWeb/TestFetchResponse.cppindex 1b1c6d7d0a2..0e510e72cb4 100644--- a/Tests/LibWeb/TestFetchResponse.cpp+++ b/Tests/LibWeb/TestFetchResponse.cpp@@ -76,7 +76,8 @@ TEST_CASE(http_redirect_fetch_releases_intermediate_response_transfer_lease)request->set_url_list({ request_url.release_value() });request->set_redirect_count(20);- auto fetch_params = Web::Fetch::Infrastructure::FetchParams::create(request, Web::Fetch::Infrastructure::FetchTimingInfo::create());+ auto algorithms = Web::Fetch::Infrastructure::FetchAlgorithms::create(Web::Fetch::Infrastructure::FetchAlgorithms::Input { Web::Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent });+ auto fetch_params = Web::Fetch::Infrastructure::FetchParams::create(request, algorithms, Web::Fetch::Infrastructure::FetchTimingInfo::create());auto response = TransferTrackingResponse::create(*vm);response->set_status(302);response->set_header_list(HTTP::HeaderList::create({ { "Location"sv, "/redirected"sv } }));