Truly independent web browser
LibWeb: Hand fetch's algorithms a ResponseView of the response
Luke Wilde3573cdcbe79b
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex 4b0c7d9998d..b30b0255046 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -378,6 +378,7 @@ set(SOURCESFetch/Infrastructure/HTTP/MIME.cppFetch/Infrastructure/HTTP/Requests.cppFetch/Infrastructure/HTTP/Responses.cpp+ Fetch/Infrastructure/HTTP/ResponseView.cppFetch/Infrastructure/IncrementalReadLoopReadRequest.cppFetch/Infrastructure/KeepaliveQuotaAccountant.cppFetch/Infrastructure/MimeTypeBlocking.cppdiff --git a/Libraries/LibWeb/CSS/FontComputer.cpp b/Libraries/LibWeb/CSS/FontComputer.cppindex aba17e98726..4b8de9a84d2 100644--- a/Libraries/LibWeb/CSS/FontComputer.cpp+++ b/Libraries/LibWeb/CSS/FontComputer.cpp@@ -237,7 +237,7 @@ void FontLoader::font_did_load_or_fail(RefPtr<Gfx::Typeface const> typeface)m_fetch_controller = nullptr;}-Optional<ByteString> FontLoader::try_load_font_mime_type_essence(Fetch::Infrastructure::Response const& response, ByteBuffer const& bytes)+Optional<ByteString> FontLoader::try_load_font_mime_type_essence(Fetch::Infrastructure::ResponseView const& response, ByteBuffer const& bytes){// FIXME: This could maybe use the format() provided in @font-face as well, since often the mime type is just application/octet-stream and we have to try every formatauto mime_type = Fetch::Infrastructure::extract_mime_type(response.header_list());diff --git a/Libraries/LibWeb/CSS/FontComputer.h b/Libraries/LibWeb/CSS/FontComputer.hindex 66aa24790bf..b5f6b49a56a 100644--- a/Libraries/LibWeb/CSS/FontComputer.h+++ b/Libraries/LibWeb/CSS/FontComputer.h@@ -174,7 +174,7 @@ public:private:virtual void visit_edges(Visitor&) override;- Optional<ByteString> try_load_font_mime_type_essence(Fetch::Infrastructure::Response const&, ByteBuffer const&);+ Optional<ByteString> try_load_font_mime_type_essence(Fetch::Infrastructure::ResponseView const&, ByteBuffer const&);void font_did_load_or_fail(RefPtr<Gfx::Typeface const>);diff --git a/Libraries/LibWeb/CSS/StyleSheetImport.cpp b/Libraries/LibWeb/CSS/StyleSheetImport.cppindex c9b78513240..1f90f7ec4b3 100644--- a/Libraries/LibWeb/CSS/StyleSheetImport.cpp+++ b/Libraries/LibWeb/CSS/StyleSheetImport.cpp@@ -21,7 +21,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/DocumentLoadEventDelayer.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/Window.h>#include <LibWeb/ReferrerPolicy/AbstractOperations.h>@@ -220,7 +220,7 @@ void StyleSheetImport::fetch()}Parser::Parser::parse_stylesheet_off_thread(Parser::ParsingParams { *document }, decoded_or_error.release_value(),- [strong_this, parent_style_sheet, document = GC::make_root(document), url = move(url), is_cors_same_origin = response->is_cors_same_origin(), referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(response->unsafe_response()), finish_loading = move(finish_loading)](Parser::RustStyleSheetParse parsed) mutable {+ [strong_this, parent_style_sheet, document = GC::make_root(document), url = move(url), is_cors_same_origin = response->is_cors_same_origin(), referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(*response->unsafe_response()->record()), finish_loading = move(finish_loading)](Parser::RustStyleSheetParse parsed) mutable {ScopeGuard guard = move(finish_loading);// NB: The sheet records its referrer policy as it is created, before its own imports start to load.auto imported_style_sheet = StyleSheetState::create(parsed.native_rules(), document.ptr(), strong_this->m_media_list.retain(), move(url), referrer_policy);diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cppindex e412cefd3e3..22fe7be6d58 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp@@ -19,7 +19,7 @@#include <LibWeb/DOM/Element.h>#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -162,7 +162,7 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_co// https://w3c.github.io/webappsec-csp/#should-block-navigation-responseDirectives::Directive::Result should_navigation_response_to_navigation_request_of_type_in_target_be_blocked_by_content_security_policy(RefPtr<Fetch::Infrastructure::Request> navigation_request,- GC::Ref<Fetch::Infrastructure::Response> navigation_response,+ GC::Ref<Fetch::Infrastructure::ResponseView> navigation_response,PolicyList const& response_csp_list,Directives::Directive::NavigationType navigation_type,GC::Ref<HTML::LocalNavigable> target)@@ -196,7 +196,7 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_o// 1. For each directive of policy:for (auto const& directive : policy->directives()) {// 1. If directive’s navigation response check returns "Allowed" when executed upon navigation request, type, navigation response, target, "response", and policy skip to the next directive.- auto directive_result = Directives::navigation_response_check(directive, *navigation_request, navigation_type, navigation_response, target_container_document_origins, Directives::Directive::CheckType::Response, policy);+ auto directive_result = Directives::navigation_response_check(directive, *navigation_request, navigation_type, navigation_response->record(), target_container_document_origins, Directives::Directive::CheckType::Response, policy);if (directive_result == Directives::Directive::Result::Allowed)continue;@@ -230,7 +230,7 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_o// 1. For each directive of policy:for (auto const& directive : policy->directives()) {// 1. If directive’s navigation response check returns "Allowed" when executed upon navigation request, type, navigation response, target, "source", and policy skip to the next directive.- auto directive_result = Directives::navigation_response_check(directive, *navigation_request, navigation_type, navigation_response, target_container_document_origins, Directives::Directive::CheckType::Source, policy);+ auto directive_result = Directives::navigation_response_check(directive, *navigation_request, navigation_type, navigation_response->record(), target_container_document_origins, Directives::Directive::CheckType::Source, policy);if (directive_result == Directives::Directive::Result::Allowed)continue;diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.hindex 60580ae8185..ec7d1a3280c 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.h@@ -19,7 +19,7 @@ namespace Web::ContentSecurityPolicy {Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_content_security_policy(NonnullRefPtr<Fetch::Infrastructure::Request> navigation_request, Directives::Directive::NavigationType navigation_type);Directives::Directive::Result should_navigation_response_to_navigation_request_of_type_in_target_be_blocked_by_content_security_policy(RefPtr<Fetch::Infrastructure::Request> navigation_request,- GC::Ref<Fetch::Infrastructure::Response> navigation_response,+ GC::Ref<Fetch::Infrastructure::ResponseView> navigation_response,ContentSecurityPolicy::PolicyList const& response_csp_list,Directives::Directive::NavigationType navigation_type,GC::Ref<HTML::LocalNavigable> target);diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 7e9908b9f75..c009dfbaa46 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -143,7 +143,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/FetchRecord.h>#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/BlobURLStore.h>#include <LibWeb/HTML/AttributeNames.h>#include <LibWeb/HTML/BeforeUnloadEvent.h>@@ -602,7 +602,7 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type// - navigation TAO check given navigationParams's response and navigationParams's origin returns success,may_expose_redirect_count = (!request.client().has_value() || request_has_eligible_referrer)- && Fetch::Fetching::navigation_tao_check(*navigation_params.response, navigation_params.origin);+ && Fetch::Fetching::navigation_tao_check(navigation_params.response->record(), navigation_params.origin);}// then set redirectCount to navigationParams's request's redirect count.diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cppindex 09074ed23af..416d8b2fde2 100644--- a/Libraries/LibWeb/DOM/DocumentLoading.cpp+++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp@@ -47,7 +47,7 @@namespace Web {-static void add_pdf_viewer_ready_listener(DOM::Document& document, GC::Ref<Fetch::Infrastructure::Response> response)+static void add_pdf_viewer_ready_listener(DOM::Document& document, GC::Ref<Fetch::Infrastructure::ResponseView> response){auto& realm = document.relevant_settings_object().realm();auto js_response = Fetch::Response::create(response, Fetch::Headers::Guard::Response);diff --git a/Libraries/LibWeb/DOM/DocumentLoading.h b/Libraries/LibWeb/DOM/DocumentLoading.hindex acec7f8c607..c7d3773eaa8 100644--- a/Libraries/LibWeb/DOM/DocumentLoading.h+++ b/Libraries/LibWeb/DOM/DocumentLoading.h@@ -9,6 +9,7 @@#include <LibGC/Heap.h>#include <LibWeb/DOM/Document.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/UserNavigationInvolvement.h>@@ -64,7 +65,7 @@ GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::LocalNavmove(navigation_id),navigable,nullptr,- response,+ Fetch::Infrastructure::ResponseView::create(response),nullptr,nullptr,move(coop_enforcement_result),diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 7f634ba0859..c44ad046b7a 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -86,7 +86,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/BlobURLStore.h>#include <LibWeb/Geometry/DOMRect.h>#include <LibWeb/Geometry/DOMRectList.h>@@ -792,7 +792,7 @@ void Element::download_the_hyperlink(Optional<Utf16String> hyperlink_suffix, HTM// 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::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) {+ 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::ResponseView> response) {if (response->is_network_error())return;navigable->handle_as_a_download(response->unsafe_response(), url, controller_holder->controller(), proposed_filename, interface_origin);diff --git a/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Libraries/LibWeb/Fetch/FetchMethod.cppindex 1fcbcdc88ad..3ec4bbc05ee 100644--- a/Libraries/LibWeb/Fetch/FetchMethod.cpp+++ b/Libraries/LibWeb/Fetch/FetchMethod.cpp@@ -123,7 +123,7 @@ GC::Ref<WebIDL::Promise> fetch(JS::Realm& realm, RequestInfo const& input, Bindi// 12. Set controller to the result of calling fetch given request and processResponse given response being these// steps:- auto process_response = [locally_aborted, promise_capability, request_object, response_object_holder, controller_holder, &relevant_realm](GC::Ref<Infrastructure::Response> response) {+ auto process_response = [locally_aborted, promise_capability, request_object, response_object_holder, controller_holder, &relevant_realm](GC::Ref<Infrastructure::ResponseView> response) {// 1. If locallyAborted is true, then abort these steps.if (locally_aborted->value())return;diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 87074fbb74f..3f7c3926e74 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -45,6 +45,7 @@#include <LibWeb/Fetch/Infrastructure/HTTP/CORS.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>#include <LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h>#include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>@@ -953,6 +954,8 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const{dbgln_if(WEB_FETCH_DEBUG, "Fetch: Running 'fetch response handover' with: fetch_params @ {}, response @ {}", &fetch_params, &response);+ auto response_view = Infrastructure::ResponseView::create(response);+// 1. Let timingInfo be fetchParams’s timing info.auto timing_info = fetch_params.timing_info();@@ -1085,14 +1088,14 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const};// 4. Let processResponseEndOfBody be the following steps:- auto process_response_end_of_body = [&fetch_params, &response, setup_report_timing_steps, report_timing_if_appropriate] {+ auto process_response_end_of_body = [&fetch_params, response_view, setup_report_timing_steps, report_timing_if_appropriate] {// 1-2. (See setup_report_timing_steps above)setup_report_timing_steps();- if (WebDriver::BiDi::g_network_events_enabled && !response.is_network_error())- WebDriver::BiDi::network_response_completed(fetch_params, *response.unsafe_response());+ if (WebDriver::BiDi::g_network_events_enabled && !response_view->is_network_error())+ WebDriver::BiDi::network_response_completed(fetch_params, *response_view->record()->unsafe_response());// 3. Let processResponseEndOfBodyTask be the following steps:- auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [&fetch_params, &response, report_timing_if_appropriate] {+ auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [&fetch_params, response_view, report_timing_if_appropriate] {// 1. Set fetchParams’s request’s done flag.fetch_params.request()->set_done(true);end_rendering_pending_operation(fetch_params.controller().ptr());@@ -1100,7 +1103,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// 2. If fetchParams’s process response end-of-body is non-null, then run fetchParams’s process response// end-of-body given response.if (fetch_params.algorithms()->process_response_end_of_body())- (fetch_params.algorithms()->process_response_end_of_body())(response);+ (fetch_params.algorithms()->process_response_end_of_body())(response_view);report_timing_if_appropriate();});@@ -1112,8 +1115,8 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// 5. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response// given response, with fetchParams’s task destination.if (fetch_params.algorithms()->process_response()) {- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params, &response]() {- fetch_params.algorithms()->process_response()(response);+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [&fetch_params, response_view]() {+ fetch_params.algorithms()->process_response()(response_view);}));}@@ -1245,24 +1248,24 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams constif (algorithms->process_response_consume_body()) {// 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given// response and nullOrBytes.- auto process_body = GC::create_function(GC::Heap::the(), [algorithms, &response](ByteBuffer bytes) {+ auto process_body = GC::create_function(GC::Heap::the(), [algorithms, &response, response_view](ByteBuffer bytes) {if (response.body()) {if (auto const& source = response.body()->source(); source.has_value()) {- (algorithms->process_response_consume_body())(response, *source);+ (algorithms->process_response_consume_body())(response_view, *source);return;}}- (algorithms->process_response_consume_body())(response, Core::ImmutableBytes::adopt(move(bytes)));+ (algorithms->process_response_consume_body())(response_view, Core::ImmutableBytes::adopt(move(bytes)));});// 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and// failure.- auto process_body_error = GC::create_function(GC::Heap::the(), [algorithms, &response, controller = fetch_params.controller(), setup_report_timing_steps](JS::Value) {+ auto process_body_error = GC::create_function(GC::Heap::the(), [algorithms, response_view, controller = fetch_params.controller(), setup_report_timing_steps](JS::Value) {// AD-HOC: See comment on setup_report_timing_steps above.setup_report_timing_steps();// NB: A failed read does not always close or error the body's stream, which would otherwise end this.end_rendering_pending_operation(controller.ptr());- (algorithms->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});+ (algorithms->process_response_consume_body())(response_view, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});});// 3. If internalResponse's body is null, then queue a fetch task to run processBody given null, with@@ -1271,12 +1274,12 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const// AD-HOC: For a sync XHR's body, run processBody directly (see read_body_in_parallel above;// processResponseEndOfBody already ran, right after it).if (read_body_in_parallel) {- (algorithms->process_response_consume_body())(response, Empty {});+ (algorithms->process_response_consume_body())(response_view, Empty {});} else {- Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [algorithms, &response]() {+ Infrastructure::queue_fetch_task(fetch_params.controller(), fetch_params.task_destination(), GC::create_function(GC::Heap::the(), [algorithms, response_view]() {// NB: We have to provide fully_read a callback which accepts a ByteBuffer. Since that's not// nullable, we just invoke process_response_consume_body with a null value manually here.- (algorithms->process_response_consume_body())(response, Empty {});+ (algorithms->process_response_consume_body())(response_view, Empty {});}));}}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.hindex 0b24dd5c5a5..c7149ef0db0 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h@@ -28,10 +28,10 @@ public:using ProcessRequestBodyChunkLengthFunction = Function<void(u64)>;using ProcessRequestEndOfBodyFunction = Function<void()>;- using ProcessEarlyHintsResponseFunction = Function<void(GC::Ref<Infrastructure::Response>)>;- using ProcessResponseFunction = Function<void(GC::Ref<Infrastructure::Response>)>;- using ProcessResponseEndOfBodyFunction = Function<void(GC::Ref<Infrastructure::Response>)>;- using ProcessResponseConsumeBodyFunction = Function<void(GC::Ref<Infrastructure::Response>, BodyBytes)>;+ using ProcessEarlyHintsResponseFunction = Function<void(GC::Ref<Infrastructure::ResponseView>)>;+ using ProcessResponseFunction = Function<void(GC::Ref<Infrastructure::ResponseView>)>;+ using ProcessResponseEndOfBodyFunction = Function<void(GC::Ref<Infrastructure::ResponseView>)>;+ using ProcessResponseConsumeBodyFunction = Function<void(GC::Ref<Infrastructure::ResponseView>, BodyBytes)>;using ProcessRequestBodyChunkLengthHeapFunction = GC::Ref<GC::Function<ProcessRequestBodyChunkLengthFunction::FunctionType>>;using ProcessRequestEndOfBodyHeapFunction = GC::Ref<GC::Function<ProcessRequestEndOfBodyFunction::FunctionType>>;diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cppnew file mode 100644index 00000000000..03bd778f2c2--- /dev/null+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.cpp@@ -0,0 +1,55 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibGC/Heap.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>++namespace Web::Fetch::Infrastructure {++GC_DEFINE_ALLOCATOR(ResponseView);++GC::Ref<ResponseView> ResponseView::create(GC::Ref<Response> record)+{+ return GC::Heap::the().allocate<ResponseView>(record);+}++GC::Ref<ResponseView> ResponseView::network_error(String message)+{+ return create(Response::network_error(move(message)));+}++GC::Ref<ResponseView> ResponseView::aborted_network_error()+{+ return create(Response::aborted_network_error());+}++ResponseView::ResponseView(GC::Ref<Response> record)+ : m_record(record)+{+}++void ResponseView::visit_edges(Visitor& visitor)+{+ Base::visit_edges(visitor);+ visitor.visit(m_record);+}++// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#unsafe-response+GC::Ref<ResponseView> ResponseView::unsafe_response()+{+ auto unsafe_response = m_record->unsafe_response();+ if (unsafe_response == m_record)+ return *this;+ return create(unsafe_response);+}++// https://fetch.spec.whatwg.org/#concept-response-clone+GC::Ref<ResponseView> ResponseView::clone(JS::Realm& realm) const+{+ return create(m_record->clone(realm));+}++}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.hnew file mode 100644index 00000000000..04f257c8c54--- /dev/null+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h@@ -0,0 +1,70 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibGC/Ptr.h>+#include <LibJS/Heap/Cell.h>+#include <LibWeb/Export.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>++namespace Web::Fetch::Infrastructure {++// A response as code outside the fetch algorithms reads it.+class WEB_API ResponseView final : public JS::Cell {+ GC_CELL(ResponseView, JS::Cell);+ GC_DECLARE_ALLOCATOR(ResponseView);++public:+ [[nodiscard]] static GC::Ref<ResponseView> create(GC::Ref<Response>);+ [[nodiscard]] static GC::Ref<ResponseView> network_error(String message);+ [[nodiscard]] static GC::Ref<ResponseView> aborted_network_error();++ [[nodiscard]] GC::Ref<Response> record() const { return m_record; }++ [[nodiscard]] Response::Type type() const { return m_record->type(); }+ [[nodiscard]] bool aborted() const { return m_record->aborted(); }+ [[nodiscard]] Vector<URL::URL> const& url_list() const { return m_record->url_list(); }+ [[nodiscard]] Status status() const { return m_record->status(); }+ [[nodiscard]] ByteString const& status_message() const { return m_record->status_message(); }+ [[nodiscard]] NonnullRefPtr<HTTP::HeaderList> const& header_list() const { return m_record->header_list(); }+ [[nodiscard]] GC::Ptr<Body> body() const { return m_record->body(); }+ [[nodiscard]] Optional<Response::CacheState> const& cache_state() const { return m_record->cache_state(); }+ [[nodiscard]] bool timing_allow_passed() const { return m_record->timing_allow_passed(); }+ [[nodiscard]] Vector<Vector<String>> const& navigation_timing_allow_values_list() const { return m_record->navigation_timing_allow_values_list(); }+ [[nodiscard]] Response::BodyInfo const& body_info() const { return m_record->body_info(); }+ [[nodiscard]] RedirectTaint redirect_taint() const { return m_record->redirect_taint(); }+ [[nodiscard]] Optional<Core::ImmutableBytes> const& javascript_bytecode_cache() const { return m_record->javascript_bytecode_cache(); }+ [[nodiscard]] Optional<u64> javascript_bytecode_cache_vary_key() const { return m_record->javascript_bytecode_cache_vary_key(); }+ [[nodiscard]] Optional<NonnullRefPtr<HTTP::HeaderList>> const& javascript_bytecode_cache_memory_cache_request_headers() const { return m_record->javascript_bytecode_cache_memory_cache_request_headers(); }++ [[nodiscard]] bool is_aborted_network_error() const { return m_record->is_aborted_network_error(); }+ [[nodiscard]] bool is_network_error() const { return m_record->is_network_error(); }+ [[nodiscard]] Optional<URL::URL const&> url() const { return m_record->url(); }+ [[nodiscard]] ErrorOr<Optional<URL::URL>> location_url(Optional<StringView> request_fragment) const { return m_record->location_url(request_fragment); }+ [[nodiscard]] bool is_cors_same_origin() const { return m_record->is_cors_same_origin(); }+ [[nodiscard]] bool is_cors_cross_origin() const { return m_record->is_cors_cross_origin(); }+ [[nodiscard]] Optional<String> const& network_error_message() const { return m_record->network_error_message(); }+ [[nodiscard]] MonotonicTime monotonic_response_time() const { return m_record->monotonic_response_time(); }+ [[nodiscard]] Optional<Response::NetworkTransport> const& network_transport() const { return m_record->network_transport(); }++ [[nodiscard]] GC::Ref<ResponseView> unsafe_response();+ [[nodiscard]] GC::Ref<ResponseView> clone(JS::Realm&) const;++ void release_request_transfer_lease() const { m_record->release_request_transfer_lease(); }+ void resume_body_delivery() const { m_record->resume_body_delivery(); }+ void resume_body_delivery_up_to(size_t byte_count) const { m_record->resume_body_delivery_up_to(byte_count); }+ [[nodiscard]] Vector<Core::ImmutableBytes> release_body_for_transfer() const { return m_record->release_body_for_transfer(); }++private:+ explicit ResponseView(GC::Ref<Response>);++ virtual void visit_edges(Visitor&) override;++ GC::Ref<Response> m_record;+};++}diff --git a/Libraries/LibWeb/Fetch/Response.cpp b/Libraries/LibWeb/Fetch/Response.cppindex ccd3bc4440e..17da9c1307b 100644--- a/Libraries/LibWeb/Fetch/Response.cpp+++ b/Libraries/LibWeb/Fetch/Response.cpp@@ -25,7 +25,7 @@ static Bindings::ResponseType response_type_to_bindings(Infrastructure::Responsereturn static_cast<Bindings::ResponseType>(type);}-Response::Response(GC::Ref<Infrastructure::Response> response)+Response::Response(GC::Ref<Infrastructure::ResponseView> response): m_response(response){}@@ -67,12 +67,12 @@ GC::Ptr<Infrastructure::Body> Response::body_impl()}// https://fetch.spec.whatwg.org/#response-create-GC::Ref<Response> Response::create(GC::Ref<Infrastructure::Response> response)+GC::Ref<Response> Response::create(GC::Ref<Infrastructure::ResponseView> response){return GC::Heap::the().allocate<Response>(response);}-GC::Ref<Response> Response::create(GC::Ref<Infrastructure::Response> response, Headers::Guard guard)+GC::Ref<Response> Response::create(GC::Ref<Infrastructure::ResponseView> response, Headers::Guard guard){// 1. Let responseObject be a new Response object with realm.// 2. Set responseObject’s response to response.@@ -99,8 +99,14 @@ static bool is_valid_status_text(String const& status_text)}// https://fetch.spec.whatwg.org/#initialize-a-response-WebIDL::ExceptionOr<void> Response::initialize_response(ResponseInit const& init, Optional<Infrastructure::BodyWithType> const& body)+// NB: This initializes a new response before the Response object holding it is created, so the object's response is+// complete from the start. Nothing can observe the order.+WebIDL::ExceptionOr<GC::Ref<Response>> Response::create_with_body(ResponseInit const& init, Optional<Infrastructure::BodyWithType> const& body){+ auto response = Infrastructure::Response::create();+ auto headers = Headers::create(response->header_list());+ headers->set_guard(Headers::Guard::Response);+// 1. If init["status"] is not in the range 200 to 599, inclusive, then throw a RangeError.if (init.status < 200 || init.status > 599)return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Status must be in range 200-599"_utf16 };@@ -110,30 +116,32 @@ WebIDL::ExceptionOr<void> Response::initialize_response(ResponseInit const& initreturn WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid statusText: does not match the reason-phrase token production"_utf16 };// 3. Set response’s response’s status to init["status"].- m_response->set_status(init.status);+ response->set_status(init.status);// 4. Set response’s response’s status message to init["statusText"].- m_response->set_status_message(init.status_text.to_byte_string());+ response->set_status_message(init.status_text.to_byte_string());// 5. If init["headers"] exists, then fill response’s headers with init["headers"].if (init.headers.has_value())- TRY(m_headers->fill(*init.headers));+ TRY(headers->fill(*init.headers));// 6. If body was given, then:if (body.has_value()) {// 1. If response’s status is a null body status, then throw a TypeError.- if (Infrastructure::is_null_body_status(m_response->status()))+ if (Infrastructure::is_null_body_status(response->status()))return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Response with null body status cannot have a body"_utf16 };// 2. Set response’s body to body’s body.- m_response->set_body(body->body);+ response->set_body(body->body);// 3. If body’s type is non-null and response’s header list does not contain `Content-Type`, then append (`Content-Type`, body’s type) to response’s header list.- if (body->type.has_value() && !m_response->header_list()->contains("Content-Type"sv))- m_response->header_list()->append(HTTP::Header::isomorphic_encode("Content-Type"sv, *body->type));+ if (body->type.has_value() && !response->header_list()->contains("Content-Type"sv))+ response->header_list()->append(HTTP::Header::isomorphic_encode("Content-Type"sv, *body->type));}- return {};+ auto response_object = create(Infrastructure::ResponseView::create(response));+ response_object->m_headers = headers;+ return response_object;}// https://fetch.spec.whatwg.org/#dom-response-error@@ -141,7 +149,7 @@ GC::Ref<Response> Response::error(){// The static error() method steps are to return the result of creating a Response object, given a new network error, "immutable", and this’s relevant Realm.// FIXME: How can we reliably get 'this', i.e. the object the function was called on, in IDL-defined functions?- return Response::create(Infrastructure::Response::network_error("Response created via `Response.error()`"_string), Headers::Guard::Immutable);+ return Response::create(Infrastructure::ResponseView::network_error("Response created via `Response.error()`"_string), Headers::Guard::Immutable);}// https://fetch.spec.whatwg.org/#dom-response-redirect@@ -159,28 +167,24 @@ WebIDL::ExceptionOr<GC::Ref<Response>> Response::redirect(Utf16String const& urlif (!Infrastructure::is_redirect_status(status))return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Status must be one of 301, 302, 303, 307, or 308"_utf16 };- // 4. Let responseObject be the result of creating a Response object, given a new response, "immutable", and this’s relevant Realm.- // FIXME: How can we reliably get 'this', i.e. the object the function was called on, in IDL-defined functions?- auto response_object = Response::create(Infrastructure::Response::create(), Headers::Guard::Immutable);+ // NB: Step 4 runs after steps 5 to 7, so the Response object's response is complete when it is created. Nothing+ // can observe the order.+ auto response = Infrastructure::Response::create();// 5. Set responseObject’s response’s status to status.- response_object->response()->set_status(status);+ response->set_status(status);// 6. Let value be parsedURL, serialized and isomorphic encoded.auto value = parsed_url->serialize();// 7. Append (`Location`, value) to responseObject’s response’s header list.auto header = HTTP::Header::isomorphic_encode("Location"sv, value);- response_object->response()->header_list()->append(move(header));+ response->header_list()->append(move(header));- // 8. Return responseObject.- return response_object;-}+ // 4. Let responseObject be the result of creating a Response object, given a new response, "immutable", and the current realm.+ auto response_object = Response::create(Infrastructure::ResponseView::create(response), Headers::Guard::Immutable);-WebIDL::ExceptionOr<GC::Ref<Response>> Response::create_with_body(ResponseInit const& init, Optional<Infrastructure::BodyWithType> const& body_with_type)-{- auto response_object = Response::create(Infrastructure::Response::create(), Headers::Guard::Response);- TRY(response_object->initialize_response(init, body_with_type));+ // 8. Return responseObject.return response_object;}diff --git a/Libraries/LibWeb/Fetch/Response.h b/Libraries/LibWeb/Fetch/Response.hindex d1ef54ce6f0..72b2db3273c 100644--- a/Libraries/LibWeb/Fetch/Response.h+++ b/Libraries/LibWeb/Fetch/Response.h@@ -15,7 +15,7 @@#include <LibWeb/Fetch/Body.h>#include <LibWeb/Fetch/BodyInit.h>#include <LibWeb/Fetch/Headers.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/Forward.h>#include <LibWebCommon/WebIDL/Types.h>@@ -31,8 +31,8 @@ class Response finalGC_DECLARE_ALLOCATOR(Response);public:- [[nodiscard]] static GC::Ref<Response> create(GC::Ref<Infrastructure::Response>);- [[nodiscard]] static GC::Ref<Response> create(GC::Ref<Infrastructure::Response>, Headers::Guard);+ [[nodiscard]] static GC::Ref<Response> create(GC::Ref<Infrastructure::ResponseView>);+ [[nodiscard]] static GC::Ref<Response> create(GC::Ref<Infrastructure::ResponseView>, Headers::Guard);virtual ~Response() override;@@ -47,7 +47,7 @@ public:using BodyMixin::json;using BodyMixin::text;- [[nodiscard]] GC::Ref<Infrastructure::Response> response() const { return m_response; }+ [[nodiscard]] GC::Ref<Infrastructure::ResponseView> response() const { return m_response; }[[nodiscard]] static GC::Ref<Response> error();static WebIDL::ExceptionOr<GC::Ref<Response>> redirect(Utf16String const& url, u16 status);@@ -64,15 +64,13 @@ public:[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<Response>> clone(JS::Realm&) const;private:- explicit Response(GC::Ref<Infrastructure::Response>);+ explicit Response(GC::Ref<Infrastructure::ResponseView>);virtual void visit_edges(GC::Cell::Visitor&) override;- WebIDL::ExceptionOr<void> initialize_response(ResponseInit const&, Optional<Infrastructure::BodyWithType> const&);-// https://fetch.spec.whatwg.org/#concept-response-response// A Response object has an associated response (a response).- GC::Ref<Infrastructure::Response> m_response;+ GC::Ref<Infrastructure::ResponseView> m_response;// https://fetch.spec.whatwg.org/#response-headers// A Response object also has an associated headers (null or a Headers object), initially null.diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 5d833ef28f5..90083dfab98 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -581,6 +581,7 @@ class IncrementalReadLoopReadRequest;class KeepaliveQuotaAccountant;class Request;class Response;+class ResponseView;struct BodyWithType;diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cppindex 7c4a166de79..3cd80b12760 100644--- a/Libraries/LibWeb/HTML/EventSource.cpp+++ b/Libraries/LibWeb/HTML/EventSource.cpp@@ -17,7 +17,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/CORSSettingAttribute.h>#include <LibWeb/HTML/EventLoop/EventLoop.h>#include <LibWeb/HTML/EventNames.h>@@ -115,7 +115,7 @@ WebIDL::ExceptionOr<GC::Ref<EventSource>> EventSource::create(WindowOrWorkerGlob// 14. Let processEventSourceEndOfBody given response res be the following step: if res is not a network error, then// reestablish the connection.- auto process_event_source_end_of_body = [event_source](GC::Ref<Fetch::Infrastructure::Response> response) {+ auto process_event_source_end_of_body = [event_source](GC::Ref<Fetch::Infrastructure::ResponseView> response) {if (!response->is_network_error())event_source->reestablish_the_connection();};@@ -125,7 +125,7 @@ WebIDL::ExceptionOr<GC::Ref<EventSource>> EventSource::create(WindowOrWorkerGlobFetch::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) {+ fetch_algorithms_input.process_response = [event_source](GC::Ref<Fetch::Infrastructure::ResponseView> response) {auto& realm = HTML::relevant_realm(event_source->relevant_global_object());// FIXME: If the response is CORS cross-origin, we must use its internal response to query any of its data. See:diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cppindex 98c7f22dbb8..92c507549c8 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp@@ -32,7 +32,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/EventNames.h>#include <LibWeb/HTML/HTMLImageElement.h>@@ -1030,10 +1030,10 @@ 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::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) {+ fetch_algorithms_input.process_response_consume_body = [&realm, options = GC::Ref { options }, process_response = move(process_response), entry, report_timing](GC::Ref<Fetch::Infrastructure::ResponseView> response_view, 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- response = response->unsafe_response();+ auto response = response_view->record()->unsafe_response();// 1. If bodyBytes is a byte sequence, then set response's body to bodyBytes as a body.if (auto* byte_sequence = body_bytes.get_pointer<Core::ImmutableBytes>())@@ -1330,7 +1330,7 @@ bool HTMLLinkElement::apply_link_options_from_parsed_header_attributes(LinkProce}// https://html.spec.whatwg.org/multipage/semantics.html#process-the-linked-resource-void HTMLLinkElement::process_linked_resource(bool success, Fetch::Infrastructure::Response const& response, CSS::StyleScope::OriginClean origin_clean, Core::ImmutableBytes const* body_bytes)+void HTMLLinkElement::process_linked_resource(bool success, Fetch::Infrastructure::ResponseView const& response, CSS::StyleScope::OriginClean origin_clean, Core::ImmutableBytes const* body_bytes){if (success)VERIFY(body_bytes);@@ -1388,7 +1388,7 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Bitmap const>>> decode_fav// AD-HOC: The spec is underspecified for fetching and processing rel="icon" See:// https://github.com/whatwg/html/issues/1769-void HTMLLinkElement::process_icon_resource(bool success, Fetch::Infrastructure::Response const& response, ByteBuffer body_bytes)+void HTMLLinkElement::process_icon_resource(bool success, Fetch::Infrastructure::ResponseView const& response, ByteBuffer body_bytes){if (!success)return;@@ -1412,7 +1412,7 @@ void HTMLLinkElement::process_icon_resource(bool success, Fetch::Infrastructure:}// https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:process-the-linked-resource-void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const& response, CSS::StyleScope::OriginClean origin_clean, ReadonlyBytes body_bytes)+void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastructure::ResponseView const& response, CSS::StyleScope::OriginClean origin_clean, ReadonlyBytes body_bytes){if (!document().is_fully_active())return;@@ -1496,7 +1496,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru// location stays the URL it was linked at.CSS::Parser::Parser::parse_stylesheet_off_thread(CSS::Parser::ParsingParams { document() }, maybe_decoded_string.release_value(),- [link = GC::make_root(*this), loaded_document = GC::make_root(document()), fetch_generation = m_current_fetch_generation, location = response.url_list().first(), base_url = response.url_list().last(), origin_clean, referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(response)](CSS::Parser::RustStyleSheetParse parsed) mutable {+ [link = GC::make_root(*this), loaded_document = GC::make_root(document()), fetch_generation = m_current_fetch_generation, location = response.url_list().first(), base_url = response.url_list().last(), origin_clean, referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(*response.record())](CSS::Parser::RustStyleSheetParse parsed) mutable {if (fetch_generation != link->m_current_fetch_generation || !link->m_stylesheet_processing_pending)return;// NB: An inactive document's element tasks cannot run. Release its result here.@@ -1572,7 +1572,7 @@ void HTMLLinkElement::associate_style_sheet(CSS::StyleSheetState& sheet, CSS::St// AD-HOC: The spec creates no style sheet for a link whose resource failed to load, but all major engines associate an// empty one with it. Its origin-clean flag is still set only if the response was CORS-same-origin, which a// network error never is.-void HTMLLinkElement::associate_empty_style_sheet(Fetch::Infrastructure::Response const& response, CSS::StyleScope::OriginClean origin_clean)+void HTMLLinkElement::associate_empty_style_sheet(Fetch::Infrastructure::ResponseView const& response, CSS::StyleScope::OriginClean origin_clean){// NB: A link that was removed while its resource was being fetched no longer contributes a style sheet.if (!is_browsing_context_connected())@@ -1675,7 +1675,7 @@ void HTMLLinkElement::load_fallback_favicon_if_needed(GC::Ref<DOM::Document> doc// 2. Let response be the result of fetching request.Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };- fetch_algorithms_input.process_response = [document, request](GC::Ref<Fetch::Infrastructure::Response> response) {+ fetch_algorithms_input.process_response = [document, request](GC::Ref<Fetch::Infrastructure::ResponseView> response) {auto& realm = document->relevant_settings_object().realm();auto global = GC::Ref { realm.global_object() };diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Libraries/LibWeb/HTML/HTMLLinkElement.hindex 286db1de82b..0779eee8762 100644--- a/Libraries/LibWeb/HTML/HTMLLinkElement.h+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.h@@ -190,11 +190,11 @@ private:static void preload(LinkProcessingOptions&, Function<void(Fetch::Infrastructure::Response&)> process_response = {});static void modulepreload(LinkProcessingOptions const&);- void process_linked_resource(bool success, Fetch::Infrastructure::Response const&, CSS::StyleScope::OriginClean, Core::ImmutableBytes const*);- void process_icon_resource(bool success, Fetch::Infrastructure::Response const&, ByteBuffer);- void process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const&, CSS::StyleScope::OriginClean, ReadonlyBytes);+ void process_linked_resource(bool success, Fetch::Infrastructure::ResponseView const&, CSS::StyleScope::OriginClean, Core::ImmutableBytes const*);+ void process_icon_resource(bool success, Fetch::Infrastructure::ResponseView const&, ByteBuffer);+ void process_stylesheet_resource(bool success, Fetch::Infrastructure::ResponseView const&, CSS::StyleScope::OriginClean, ReadonlyBytes);void associate_style_sheet(CSS::StyleSheetState&, CSS::StyleScope::OriginClean);- void associate_empty_style_sheet(Fetch::Infrastructure::Response const&, CSS::StyleScope::OriginClean);+ void associate_empty_style_sheet(Fetch::Infrastructure::ResponseView const&, CSS::StyleScope::OriginClean);void finish_processing_stylesheet_resource(u64 fetch_generation);void cancel_pending_stylesheet_processing();void stop_blocking_on_style_sheet();diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex e55ce5961bd..94796a7c598 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -32,7 +32,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/BlobURLStore.h>#include <LibWeb/HTML/AudioTrack.h>#include <LibWeb/HTML/AudioTrackList.h>@@ -1909,7 +1909,7 @@ void HTMLMediaElement::load_local_resource(MediaProvider const& media_provider,}// https://html.spec.whatwg.org/multipage/media.html#verify-a-media-response-Optional<Utf16String> HTMLMediaElement::verify_response_or_get_failure_reason(GC::Ref<Fetch::Infrastructure::Response> response, ByteRange const& byte_range)+Optional<Utf16String> HTMLMediaElement::verify_response_or_get_failure_reason(GC::Ref<Fetch::Infrastructure::ResponseView> response, ByteRange const& byte_range){// 1. If response is a network error, then return false.if (response->is_network_error()) {diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.hindex a723f1ac92b..9f093b41255 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h@@ -275,7 +275,7 @@ private:void add_current_video_sink(Media::VideoSinkHandle);void release_active_video_sink();- Optional<Utf16String> verify_response_or_get_failure_reason(GC::Ref<Fetch::Infrastructure::Response>, ByteRange const&);+ Optional<Utf16String> verify_response_or_get_failure_reason(GC::Ref<Fetch::Infrastructure::ResponseView>, ByteRange const&);bool should_hold_screen_wake_lock() const;void update_screen_wake_lock();diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cppindex 641a37733b5..c0654262fc3 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp@@ -23,6 +23,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/DecodedImageData.h>#include <LibWeb/HTML/HTMLMediaElement.h>@@ -281,7 +282,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()request->set_use_url_credentials(true);Fetch::Infrastructure::FetchAlgorithms::Input fetch_algorithms_input { Fetch::Engine::BodyIntent::DeliverStreamToConsumerAgent };- fetch_algorithms_input.process_response = [this](GC::Ref<Fetch::Infrastructure::Response> response) {+ fetch_algorithms_input.process_response = [this](GC::Ref<Fetch::Infrastructure::ResponseView> response) {auto& realm = HTML::relevant_realm(*this);auto& global = document().relevant_settings_object().realm().global_object();@@ -303,10 +304,8 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()return;}- if (response->type() == Fetch::Infrastructure::Response::Type::Opaque || response->type() == Fetch::Infrastructure::Response::Type::OpaqueRedirect) {- auto& filtered_response = static_cast<Fetch::Infrastructure::FilteredResponse&>(*response);- response = filtered_response.internal_response();- }+ if (response->type() == Fetch::Infrastructure::Response::Type::Opaque || response->type() == Fetch::Infrastructure::Response::Type::OpaqueRedirect)+ response = response->unsafe_response();auto on_data_read = GC::create_function(GC::Heap::the(), [this, response](ByteBuffer data) {resource_did_load(response, data);@@ -353,7 +352,7 @@ void HTMLObjectElement::resource_did_fail()}// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#object-type-detection-void HTMLObjectElement::resource_did_load(Fetch::Infrastructure::Response const& response, ReadonlyBytes data)+void HTMLObjectElement::resource_did_load(Fetch::Infrastructure::ResponseView const& response, ReadonlyBytes data){ScopeGuard guard { [&]() { m_document_load_event_delayer_for_resource_load.take_last(); } };@@ -437,7 +436,7 @@ void HTMLObjectElement::resource_did_load(Fetch::Infrastructure::Response const&}// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-object-element:plugin-11-void HTMLObjectElement::run_object_representation_handler_steps(Fetch::Infrastructure::Response const& response, MimeSniff::MimeType const& resource_type, ReadonlyBytes data)+void HTMLObjectElement::run_object_representation_handler_steps(Fetch::Infrastructure::ResponseView const& response, MimeSniff::MimeType const& resource_type, ReadonlyBytes data){// 3.9. Handler: Handle the content as given by the first of the following cases that matches:diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.hindex af766f9507c..01e0be23d03 100644--- a/Libraries/LibWeb/HTML/HTMLObjectElement.h+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h@@ -74,14 +74,14 @@ private:bool has_ancestor_media_element_or_object_element_not_showing_fallback_content() const;void queue_element_task_to_run_object_representation_steps();- void run_object_representation_handler_steps(Fetch::Infrastructure::Response const&, MimeSniff::MimeType const&, ReadonlyBytes);+ void run_object_representation_handler_steps(Fetch::Infrastructure::ResponseView const&, MimeSniff::MimeType const&, ReadonlyBytes);void run_object_representation_completed_steps(Representation);void run_object_representation_fallback_steps();void load_image();void update_layout_and_child_objects(Representation);- void resource_did_load(Fetch::Infrastructure::Response const&, ReadonlyBytes);+ void resource_did_load(Fetch::Infrastructure::ResponseView const&, ReadonlyBytes);void resource_did_fail();// ^DOM::Elementdiff --git a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp b/Libraries/LibWeb/HTML/HTMLTrackElement.cppindex 663aad66e00..726462121ef 100644--- a/Libraries/LibWeb/HTML/HTMLTrackElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLTrackElement.cpp@@ -13,7 +13,7 @@#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/HTMLMediaElement.h>#include <LibWeb/HTML/HTMLTrackElement.h>#include <LibWeb/HTML/PotentialCORSRequest.h>diff --git a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Libraries/LibWeb/HTML/HTMLVideoElement.cppindex 8e49a8774b8..31ca229b5fe 100644--- a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLVideoElement.cpp@@ -22,7 +22,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/AudioTrackList.h>#include <LibWeb/HTML/EventNames.h>#include <LibWeb/HTML/HTMLVideoElement.h>@@ -323,10 +323,8 @@ WebIDL::ExceptionOr<void> HTMLVideoElement::determine_element_poster_frame(Optioreturn;}- if (response->type() == Fetch::Infrastructure::Response::Type::Opaque || response->type() == Fetch::Infrastructure::Response::Type::OpaqueRedirect) {- auto& filtered_response = static_cast<Fetch::Infrastructure::FilteredResponse&>(*response);- response = filtered_response.internal_response();- }+ if (response->type() == Fetch::Infrastructure::Response::Type::Opaque || response->type() == Fetch::Infrastructure::Response::Type::OpaqueRedirect)+ response = response->unsafe_response();if (!response->body()) {finalize(self, nullptr);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex dabb68ea36e..67cfd7a51a7 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -49,6 +49,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/CheckUnloadingCanceledState.h>#include <LibWeb/HTML/DocumentState.h>@@ -156,7 +157,7 @@ struct NavigationParamsFetchStateHolder : public JS::Cell {{}- GC::Ptr<Fetch::Infrastructure::Response> response;+ GC::Ptr<Fetch::Infrastructure::ResponseView> response;Optional<URL::Origin> response_origin;GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller;OpenerPolicyEnforcementResult coop_enforcement_result;@@ -479,7 +480,7 @@ static Optional<u64> response_content_length(HTTP::HeaderList const& headers)return {};}-void LocalNavigable::start_download_for_response(GC::Ref<Fetch::Infrastructure::Response> response, URL::URL const& download_url, ByteString suggested_filename, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller)+void LocalNavigable::start_download_for_response(GC::Ref<Fetch::Infrastructure::ResponseView> response, URL::URL const& download_url, ByteString suggested_filename, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller){auto active_window = this->active_window();if (!active_window) {@@ -526,7 +527,7 @@ void LocalNavigable::start_download_for_response(GC::Ref<Fetch::Infrastructure::}// https://html.spec.whatwg.org/multipage/links.html#handle-as-a-download-void LocalNavigable::handle_as_a_download(GC::Ref<Fetch::Infrastructure::Response> response, URL::URL const& fallback_url, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller, Optional<ByteString> proposed_filename, Optional<URL::Origin> interface_origin)+void LocalNavigable::handle_as_a_download(GC::Ref<Fetch::Infrastructure::ResponseView> response, URL::URL const& fallback_url, GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller, Optional<ByteString> proposed_filename, Optional<URL::Origin> interface_origin){if (!response->body())return;@@ -563,7 +564,7 @@ static bool handle_navigation_response_as_download(GC::Ref<NavigationParams> navtiming_info = navigation_params->fetch_controller->timing_info();if (timing_info) {auto metadata = WebDriver::BiDi::network_response_for_navigation(- *navigation_params->request, *timing_info, *response);+ *navigation_params->request, *timing_info, *response->record());if (metadata.has_value())network_response = metadata.release_value();}@@ -578,7 +579,7 @@ static bool handle_navigation_response_as_download(GC::Ref<NavigationParams> navif (network_response.is_object() && navigation_params->navigable)WebDriver::BiDi::network_navigation_response_finished(*navigation_params->navigable, network_response.as_object(),- *response, nullptr, "Navigation download was rejected"sv);+ *response->record(), nullptr, "Navigation download was rejected"sv);};// FIXME: Implement the WebDriver BiDi download will begin/end hooks.@@ -2208,7 +2209,7 @@ static GC::Ref<NavigationParams> create_navigation_params_from_a_srcdoc_resourcemove(navigation_id),navigable,nullptr,- response,+ Fetch::Infrastructure::ResponseView::create(response),nullptr,nullptr,move(coop_enforcement_result),@@ -2261,7 +2262,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation// specification assumes the parent environment is still available here, but browser engines// abandon this stale detached frame navigation instead of continuing it against a discarded// parent.- state_holder->response = Fetch::Infrastructure::Response::network_error(realm.vm(), "Parent document is no longer active"_string);+ state_holder->response = Fetch::Infrastructure::ResponseView::network_error("Parent document is no longer active"_string);fetch_completion_steps->function()();return;}@@ -2284,7 +2285,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation// 3. If the result of should navigation request of type be blocked by Content Security Policy? given request and cspNavigationType is "Blocked", then set response to a network error and break. [CSP]if (ContentSecurityPolicy::should_navigation_request_of_type_be_blocked_by_content_security_policy(state_holder->request, state_holder->csp_navigation_type) == ContentSecurityPolicy::Directives::Directive::Result::Blocked) {- state_holder->response = Fetch::Infrastructure::Response::network_error(realm.vm(), "Blocked by Content Security Policy"_string);+ state_holder->response = Fetch::Infrastructure::ResponseView::network_error("Blocked by Content Security Policy"_string);fetch_completion_steps->function()();return;}@@ -2299,7 +2300,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation// FIXME: Let processEarlyHintsResponse be the following algorithm given a response earlyResponse:// Let processResponse be the following algorithm given a response fetchedResponse:- auto process_response = [state_holder](GC::Ref<Fetch::Infrastructure::Response> fetch_response) {+ auto process_response = [state_holder](GC::Ref<Fetch::Infrastructure::ResponseView> fetch_response) {// 1. Set response to fetchedResponse.state_holder->response = fetch_response;VERIFY(state_holder->continuation_steps);@@ -2400,7 +2401,7 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigationif (state_holder->final_sandbox_flags != SandboxingFlagSet {} && state_holder->response_coop.value != OpenerPolicyValue::UnsafeNone) {// AD-HOC: Stop the fetch, as nothing will consume the response this replaces.state_holder->fetch_controller->stop_fetch();- state_holder->response = Fetch::Infrastructure::Response::network_error(realm.vm(), "Opener policy on a sandboxed navigation response"_string);+ state_holder->response = Fetch::Infrastructure::ResponseView::network_error("Opener policy on a sandboxed navigation response"_string);fetch_completion_steps->function()();return;}@@ -2422,10 +2423,10 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigationif (auto parent = state_holder->navigable->parent()) {auto container_document_origin = parent->active_document_origin();if (container_document_origin.has_value()- && Fetch::Fetching::cross_origin_resource_policy_check(*container_document_origin, state_holder->navigable->container_document_embedder_policy(), *state_holder->response, Fetch::Fetching::ForNavigation::Yes) == Fetch::Infrastructure::RequestOrResponseBlocking::Blocked) {+ && Fetch::Fetching::cross_origin_resource_policy_check(*container_document_origin, state_holder->navigable->container_document_embedder_policy(), *state_holder->response->record(), Fetch::Fetching::ForNavigation::Yes) == Fetch::Infrastructure::RequestOrResponseBlocking::Blocked) {// AD-HOC: Stop the fetch, as nothing will consume the response this replaces.state_holder->fetch_controller->stop_fetch();- state_holder->response = Fetch::Infrastructure::Response::network_error(realm.vm(), "Blocked by Cross-Origin-Resource-Policy"_string);+ state_holder->response = Fetch::Infrastructure::ResponseView::network_error("Blocked by Cross-Origin-Resource-Policy"_string);fetch_completion_steps->function()();return;}@@ -4099,7 +4100,7 @@ GC::Ptr<DOM::Document> LocalNavigable::evaluate_javascript_url(URL::URL const& unavigation_id,this,nullptr,- response,+ Fetch::Infrastructure::ResponseView::create(response),nullptr,nullptr,move(coop_enforcement_result),diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.hindex 58e56a11ed8..d9919f6fad3 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.h+++ b/Libraries/LibWeb/HTML/LocalNavigable.h@@ -181,7 +181,7 @@ public:GC::Ptr<Navigable> find_a_navigable_by_target_name(Utf16View name);bool is_familiar_with(Navigable&);- void handle_as_a_download(GC::Ref<Fetch::Infrastructure::Response>, URL::URL const& fallback_url, GC::Ptr<Fetch::Infrastructure::FetchController>, Optional<ByteString> proposed_filename, Optional<URL::Origin> interface_origin);+ void handle_as_a_download(GC::Ref<Fetch::Infrastructure::ResponseView>, URL::URL const& fallback_url, GC::Ptr<Fetch::Infrastructure::FetchController>, Optional<ByteString> proposed_filename, Optional<URL::Origin> interface_origin);void inform_the_navigation_api_about_aborting_navigation();@@ -487,7 +487,7 @@ private:void clear_parent_compositor_context();void destroy_compositor_context();- void start_download_for_response(GC::Ref<Fetch::Infrastructure::Response>, URL::URL const& download_url, ByteString suggested_filename, GC::Ptr<Fetch::Infrastructure::FetchController>);+ void start_download_for_response(GC::Ref<Fetch::Infrastructure::ResponseView>, URL::URL const& download_url, ByteString suggested_filename, GC::Ptr<Fetch::Infrastructure::FetchController>);// A request toward the position a scroll is already headed for joins that scroll rather than restarting it, so one// scroll can owe more than one promise.diff --git a/Libraries/LibWeb/HTML/NavigateParams.cpp b/Libraries/LibWeb/HTML/NavigateParams.cppindex 0f9c095a943..69fea0ae632 100644--- a/Libraries/LibWeb/HTML/NavigateParams.cpp+++ b/Libraries/LibWeb/HTML/NavigateParams.cpp@@ -6,7 +6,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/File.h>#include <LibWeb/HTML/NavigateParams.h>#include <LibWeb/HTML/Navigation.h>diff --git a/Libraries/LibWeb/HTML/NavigateParams.h b/Libraries/LibWeb/HTML/NavigateParams.hindex ca14863045a..ad3aa0c55e5 100644--- a/Libraries/LibWeb/HTML/NavigateParams.h+++ b/Libraries/LibWeb/HTML/NavigateParams.h@@ -32,7 +32,7 @@ struct NavigateParams {URL::URL url;GC::Ptr<DOM::Document> source_document = nullptr;DocumentResource document_resource = Empty {};- GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;+ GC::Ptr<Fetch::Infrastructure::ResponseView> response = nullptr;bool exceptions_enabled = false;Bindings::NavigationHistoryBehavior history_handling = Bindings::NavigationHistoryBehavior::Auto;Optional<StorageSerializationRecord> navigation_api_state = {};@@ -49,7 +49,7 @@ struct NavigateParams {struct PreparedNavigation {URL::URL url;DocumentResource document_resource;- GC::Ptr<Fetch::Infrastructure::Response> response;+ GC::Ptr<Fetch::Infrastructure::ResponseView> response;Bindings::NavigationHistoryBehavior history_handling;Optional<StorageSerializationRecord> navigation_api_state;Optional<GC::ConservativeVector<XHR::FormDataEntry>> form_data_entry_list;diff --git a/Libraries/LibWeb/HTML/NavigationParams.cpp b/Libraries/LibWeb/HTML/NavigationParams.cppindex 5258d06feed..4cacf639474 100644--- a/Libraries/LibWeb/HTML/NavigationParams.cpp+++ b/Libraries/LibWeb/HTML/NavigationParams.cpp@@ -9,6 +9,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/Fetch/Engine/NetworkTransportHandle.h>#include <LibWeb/Fetch/Infrastructure/FetchController.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/NavigationParams.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -60,7 +61,7 @@ void NonFetchSchemeNavigationParams::visit_edges(Visitor& visitor)}// https://html.spec.whatwg.org/multipage/document-lifecycle.html#check-a-navigation-response's-adherence-to-x-frame-options-bool check_a_navigation_responses_adherence_to_x_frame_options(GC::Ptr<Fetch::Infrastructure::Response> response, LocalNavigable* navigable, ContentSecurityPolicy::PolicyList const& csp_list, URL::Origin destination_origin)+bool check_a_navigation_responses_adherence_to_x_frame_options(GC::Ptr<Fetch::Infrastructure::ResponseView> response, LocalNavigable* navigable, ContentSecurityPolicy::PolicyList const& csp_list, URL::Origin destination_origin){// 1. If navigable is not a child navigable, then return true.if (!navigable->parent()) {diff --git a/Libraries/LibWeb/HTML/NavigationParams.h b/Libraries/LibWeb/HTML/NavigationParams.hindex 21002d802bb..26089749b80 100644--- a/Libraries/LibWeb/HTML/NavigationParams.h+++ b/Libraries/LibWeb/HTML/NavigationParams.h@@ -56,7 +56,7 @@ struct NavigationParams : GC::Cell {RefPtr<Fetch::Infrastructure::Request> request;// a response that ultimately was navigated to (potentially a network error)- GC::Ptr<Fetch::Infrastructure::Response> response;+ GC::Ptr<Fetch::Infrastructure::ResponseView> response;// null or a fetch controllerGC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller { nullptr };@@ -130,7 +130,7 @@ protected:Optional<Utf16String> id,GC::Ptr<LocalNavigable> navigable,RefPtr<Fetch::Infrastructure::Request> request,- GC::Ptr<Fetch::Infrastructure::Response> response,+ GC::Ptr<Fetch::Infrastructure::ResponseView> response,GC::Ptr<Fetch::Infrastructure::FetchController> fetch_controller,GC::Ptr<GC::Function<void(DOM::Document&)>> commit_early_hints,OpenerPolicyEnforcementResult coop_enforcement_result,@@ -221,6 +221,6 @@ using NavigationParamsVariant = Variant<NavigationParamsNullOrError, GC::Ref<Nav// Returns whether a fetch controller or network transport was stopped.bool stop_body_delivery(NavigationParams::BodyDelivery const&);-bool check_a_navigation_responses_adherence_to_x_frame_options(GC::Ptr<Fetch::Infrastructure::Response> response, LocalNavigable* navigable, ContentSecurityPolicy::PolicyList const& csp_list, URL::Origin destination_origin);+bool check_a_navigation_responses_adherence_to_x_frame_options(GC::Ptr<Fetch::Infrastructure::ResponseView> response, LocalNavigable* navigable, ContentSecurityPolicy::PolicyList const& csp_list, URL::Origin destination_origin);}diff --git a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cppindex fa5d4d07f99..0b0c28ef81e 100644--- a/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp+++ b/Libraries/LibWeb/HTML/NavigationParamsDescriptor.cpp@@ -12,7 +12,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/Blob.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/NavigationParamsDescriptor.h>@@ -60,7 +60,7 @@ static Optional<ByteBuffer> copy_body_source(Fetch::Infrastructure::Body const&return {};}-static NavigationResponseDescriptor create_navigation_response_descriptor(Fetch::Infrastructure::Response const& response, Fetch::Infrastructure::Request const* request, Fetch::Infrastructure::FetchTimingInfo const* timing_info)+static NavigationResponseDescriptor create_navigation_response_descriptor(Fetch::Infrastructure::ResponseView const& response, Fetch::Infrastructure::Request const* request, Fetch::Infrastructure::FetchTimingInfo const* timing_info){Vector<HTTP::Header> headers;headers.ensure_capacity(response.header_list()->headers().size());@@ -83,7 +83,7 @@ static NavigationResponseDescriptor create_navigation_response_descriptor(Fetch:body = body_bytes.release_value();}- auto network_response = request && timing_info && response.network_transport().has_value() ? WebDriver::BiDi::network_response_for_navigation(*request, *timing_info, response) : Optional<JsonObject> {};+ auto network_response = request && timing_info && response.network_transport().has_value() ? WebDriver::BiDi::network_response_for_navigation(*request, *timing_info, *response.record()) : Optional<JsonObject> {};return {.url_list = response.url_list(),.status = response.status(),@@ -270,7 +270,7 @@ static Function<void(Optional<StringView>)> network_navigation_response_observer};}-static ErrorOr<GC::Ref<Fetch::Infrastructure::Response>> create_navigation_response_from_descriptor(JS::Realm& realm, LocalNavigable& navigable, NavigationResponseDescriptor descriptor, RefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, RefPtr<NavigationResponseNetworkEventState> network_response_state)+static ErrorOr<GC::Ref<Fetch::Infrastructure::ResponseView>> create_navigation_response_from_descriptor(JS::Realm& realm, LocalNavigable& navigable, NavigationResponseDescriptor descriptor, RefPtr<Fetch::Infrastructure::FetchTimingInfo> timing_info, RefPtr<NavigationResponseNetworkEventState> network_response_state){auto response = descriptor.network_error_message.has_value()? Fetch::Infrastructure::Response::network_error(realm.vm(), move(*descriptor.network_error_message))@@ -296,7 +296,7 @@ static ErrorOr<GC::Ref<Fetch::Infrastructure::Response>> create_navigation_resporeturn Error::from_string_literal("Unable to adopt transferred navigation response body");response->set_body(body);}- return response;+ return Fetch::Infrastructure::ResponseView::create(response);}ErrorOr<NavigationParamsVariant> create_navigation_params_from_descriptor(JS::Realm& realm, LocalNavigable& navigable, NavigationParamsVariantDescriptor descriptor)diff --git a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cppindex 49d575e1bb0..96a634a3b8f 100644--- a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp+++ b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.cpp@@ -13,7 +13,7 @@#include <LibWeb/DOM/Document.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/HTMLLinkElement.h>#include <LibWeb/HTML/Parser/HTMLEncodingDetection.h>#include <LibWeb/HTML/Parser/HTMLParser.h>@@ -28,12 +28,12 @@ static Utf16String utf16_string_from_standardized_encoding_label(StringView labereturn Utf16String::from_ascii_without_validation(label.bytes());}-GC::Ref<IncrementalDocumentParser> IncrementalDocumentParser::create(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response, GC::Ptr<DOM::Document> container_document)+GC::Ref<IncrementalDocumentParser> IncrementalDocumentParser::create(GC::Ref<DOM::Document> document, Fetch::Infrastructure::ResponseView const& response, GC::Ptr<DOM::Document> container_document){return GC::Heap::the().allocate<IncrementalDocumentParser>(document, response, container_document);}-IncrementalDocumentParser::IncrementalDocumentParser(GC::Ref<DOM::Document> document, Fetch::Infrastructure::Response const& response, GC::Ptr<DOM::Document> container_document)+IncrementalDocumentParser::IncrementalDocumentParser(GC::Ref<DOM::Document> document, Fetch::Infrastructure::ResponseView const& response, GC::Ptr<DOM::Document> container_document): m_document(document), m_container_document(container_document), m_body(response.body())diff --git a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.hindex f275a52e4f4..cd75df5fb42 100644--- a/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h+++ b/Libraries/LibWeb/HTML/Parser/IncrementalDocumentParser.h@@ -28,13 +28,13 @@ class WEB_API IncrementalDocumentParser final : public JS::Cell {GC_DECLARE_ALLOCATOR(IncrementalDocumentParser);public:- static GC::Ref<IncrementalDocumentParser> create(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&, GC::Ptr<DOM::Document> container_document);+ static GC::Ref<IncrementalDocumentParser> create(GC::Ref<DOM::Document>, Fetch::Infrastructure::ResponseView const&, GC::Ptr<DOM::Document> container_document);void start();void set_allow_declarative_shadow_roots(HTMLParser::AllowDeclarativeShadowRoots);private:- IncrementalDocumentParser(GC::Ref<DOM::Document>, Fetch::Infrastructure::Response const&, GC::Ptr<DOM::Document> container_document);+ IncrementalDocumentParser(GC::Ref<DOM::Document>, Fetch::Infrastructure::ResponseView const&, GC::Ptr<DOM::Document> container_document);virtual void visit_edges(Cell::Visitor&) override;diff --git a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cppindex 557c9019086..a4de865af1f 100644--- a/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp+++ b/Libraries/LibWeb/HTML/Parser/SpeculativeHTMLParser.cpp@@ -17,6 +17,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>#include <LibWeb/HTML/CORSSettingAttribute.h>#include <LibWeb/HTML/Parser/HTMLParser.h>@@ -145,7 +146,8 @@ void issue_speculative_fetch(JS::Realm& realm, DOM::Document& document, URL::URL// 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::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) {+ fetch_algorithms_input.process_response_consume_body = [&realm, document = GC::Ref { document }, parser = GC::Weak { document.active_parser() }, request](GC::Ref<Fetch::Infrastructure::ResponseView> response_view, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {+ auto response = response_view->record();auto* byte_sequence = body_bytes.get_pointer<Core::ImmutableBytes>();if (response->is_network_error() || !byte_sequence)return;diff --git a/Libraries/LibWeb/HTML/PolicyContainers.cpp b/Libraries/LibWeb/HTML/PolicyContainers.cppindex 7242847d487..21ecf9f7e03 100644--- a/Libraries/LibWeb/HTML/PolicyContainers.cpp+++ b/Libraries/LibWeb/HTML/PolicyContainers.cpp@@ -11,7 +11,7 @@#include <LibWeb/ContentSecurityPolicy/Directives/Names.h>#include <LibWeb/ContentSecurityPolicy/Policy.h>#include <LibWeb/ContentSecurityPolicy/PolicyList.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/BlobURLStore.h>#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -39,7 +39,7 @@ bool url_requires_storing_the_policy_container_in_history(URL::URL const& url)}// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-policy-container-from-a-fetch-response-NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ptr<Environment> environment)+NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(GC::Ref<Fetch::Infrastructure::ResponseView const> response, GC::Ptr<Environment> environment){// 1. If response's URL's scheme is "blob", then return a clone of response's URL's blob URL entry's environment's// policy container.@@ -58,7 +58,7 @@ NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(Gauto result = PolicyContainer::create();// 3. Set result's CSP list to the result of parsing a response's Content Security Policies given response.- result->csp_list = ContentSecurityPolicy::Policy::parse_a_responses_content_security_policies(response);+ result->csp_list = ContentSecurityPolicy::Policy::parse_a_responses_content_security_policies(response->record());// 4. If environment is non-null, then set result's embedder policy to the result of obtaining an embedder policy// given response and environment. Otherwise, set it to "unsafe-none".@@ -67,7 +67,7 @@ NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(G// 5. Set result's referrer policy to the result of parsing the `Referrer-Policy` header given response.// [REFERRERPOLICY]- auto parsed_referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(response);+ auto parsed_referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(response->record());if (parsed_referrer_policy != ReferrerPolicy::ReferrerPolicy::EmptyString)result->referrer_policy = parsed_referrer_policy;diff --git a/Libraries/LibWeb/HTML/PolicyContainers.h b/Libraries/LibWeb/HTML/PolicyContainers.hindex 9b3892473a0..fbafab93ed2 100644--- a/Libraries/LibWeb/HTML/PolicyContainers.h+++ b/Libraries/LibWeb/HTML/PolicyContainers.h@@ -81,7 +81,7 @@ private:[[nodiscard]] bool url_requires_storing_the_policy_container_in_history(URL::URL const& url);// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-policy-container-from-a-fetch-response-[[nodiscard]] NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ptr<Environment> environment);+[[nodiscard]] NonnullRefPtr<PolicyContainer> create_a_policy_container_from_a_fetch_response(GC::Ref<Fetch::Infrastructure::ResponseView const> response, GC::Ptr<Environment> environment);[[nodiscard]] NonnullRefPtr<PolicyContainer> create_a_policy_container_from_serialized_policy_container(SerializedPolicyContainer const&);diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cppindex 6130b5d7afc..640c94424c9 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp@@ -33,7 +33,7 @@#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/Fetch/Infrastructure/NetworkPartitionKey.h>#include <LibWeb/HTML/EventLoop/EventLoop.h>#include <LibWeb/HTML/HTMLScriptElement.h>@@ -140,7 +140,7 @@ static ByteBuffer take_body_bytes_as_byte_buffer(Fetch::Infrastructure::FetchAlgreturn body_bytes.get<Core::ImmutableBytes>().copy_to_byte_buffer().release_value_but_fixme_should_propagate_errors();}-static Optional<BytecodeCacheContext> bytecode_cache_context_for_request(Fetch::Infrastructure::Request const& request, Fetch::Infrastructure::Response const& response, URL::URL const& response_url)+static Optional<BytecodeCacheContext> bytecode_cache_context_for_request(Fetch::Infrastructure::Request const& request, Fetch::Infrastructure::ResponseView const& response, URL::URL const& response_url){if (!Fetch::Infrastructure::is_http_or_https_scheme(response_url.scheme()))return {};@@ -895,7 +895,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scriauto& realm = settings_object.realm();// 1. Let response be null.- IGNORE_USE_IN_ESCAPING_LAMBDA GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;+ IGNORE_USE_IN_ESCAPING_LAMBDA GC::Ptr<Fetch::Infrastructure::ResponseView> response = nullptr;// 2. Let bodyBytes be null.Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes;@@ -910,7 +910,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scrirequest->set_parser_metadata(Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted);request->set_use_url_credentials(true);- auto process_response_consume_body = [&response, &body_bytes](GC::Ref<Fetch::Infrastructure::Response> res, Fetch::Infrastructure::FetchAlgorithms::BodyBytes bb) {+ auto process_response_consume_body = [&response, &body_bytes](GC::Ref<Fetch::Infrastructure::ResponseView> res, Fetch::Infrastructure::FetchAlgorithms::BodyBytes bb) {// 1. Set bodyBytes to bb.body_bytes = move(bb);@@ -1098,7 +1098,7 @@ void fetch_single_module_script(JS::Realm& realm,// 13. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.// In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:- auto process_response_consume_body = [request, &module_map, url, module_type, &settings_object, options = options](GC::Ref<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) mutable {+ auto process_response_consume_body = [request, &module_map, url, module_type, &settings_object, options = options](GC::Ref<Fetch::Infrastructure::ResponseView> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) mutable {auto internal_response = response->unsafe_response();// 1. If any of the following are true:@@ -1124,7 +1124,7 @@ void fetch_single_module_script(JS::Realm& realm,// INTEROP: Other browsers also honor the header of a CORS cross-origin response, whose filtered header list// hides it. The policy only applies to the fetches of this module's descendants, whose referrer is// this module's own URL.- auto referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(*internal_response);+ auto referrer_policy = ReferrerPolicy::parse_a_referrer_policy_from_a_referrer_policy_header(internal_response->record());// 5. If referrerPolicy is not the empty string, set options's referrer policy to referrerPolicy.if (referrer_policy != ReferrerPolicy::ReferrerPolicy::EmptyString)diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cppindex b0f6d9c59b7..6d445ae98fb 100644--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp@@ -14,7 +14,7 @@#include <LibWeb/Fetch/Infrastructure/FetchController.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/AnimatedBitmapDecodedImageData.h>#include <LibWeb/HTML/BitmapDecodedImageData.h>#include <LibWeb/HTML/DecodedImageData.h>@@ -145,7 +145,7 @@ void SharedResourceRequest::fetch_resource(NonnullRefPtr<Fetch::Infrastructure::GC::Weak weak_this { *this };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) {+ fetch_algorithms_input.process_response = [weak_this, &realm, request](GC::Ref<Fetch::Infrastructure::ResponseView> response) {auto self = weak_this.ptr();if (!self)return;diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WorkerGlobalScope.cppindex 03e48cc4019..d6ba23852ea 100644--- a/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp+++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.cpp@@ -194,7 +194,7 @@ NonnullRefPtr<PolicyContainer> WorkerGlobalScope::policy_container() const}// https://html.spec.whatwg.org/multipage/browsers.html#initialize-worker-policy-container-void WorkerGlobalScope::initialize_policy_container(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ref<EnvironmentSettingsObject> environment)+void WorkerGlobalScope::initialize_policy_container(GC::Ref<Fetch::Infrastructure::ResponseView const> response, GC::Ref<EnvironmentSettingsObject> environment){// 1. If workerGlobalScope's url is local but its scheme is not "blob":if (m_url.has_value() && Fetch::Infrastructure::is_local_url(m_url.value()) && m_url->scheme() != "blob"sv) {diff --git a/Libraries/LibWeb/HTML/WorkerGlobalScope.h b/Libraries/LibWeb/HTML/WorkerGlobalScope.hindex 65f53877868..e783d20c9c4 100644--- a/Libraries/LibWeb/HTML/WorkerGlobalScope.h+++ b/Libraries/LibWeb/HTML/WorkerGlobalScope.h@@ -135,7 +135,7 @@ public:bool is_closing() const { return m_closing; }- void initialize_policy_container(GC::Ref<Fetch::Infrastructure::Response const> response, GC::Ref<EnvironmentSettingsObject> environment);+ void initialize_policy_container(GC::Ref<Fetch::Infrastructure::ResponseView const> response, GC::Ref<EnvironmentSettingsObject> environment);[[nodiscard]] bool check_embedder_policy(EmbedderPolicy const& owner_policy) const;[[nodiscard]] ContentSecurityPolicy::Directives::Directive::Result run_csp_initialization() const;diff --git a/Libraries/LibWeb/SVG/SVGScriptElement.cpp b/Libraries/LibWeb/SVG/SVGScriptElement.cppindex 6fad881ddb0..633010f9d20 100644--- a/Libraries/LibWeb/SVG/SVGScriptElement.cpp+++ b/Libraries/LibWeb/SVG/SVGScriptElement.cpp@@ -12,7 +12,7 @@#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/Scripting/ClassicScript.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/Namespace.h>diff --git a/Libraries/LibWeb/ServiceWorker/Cache.cpp b/Libraries/LibWeb/ServiceWorker/Cache.cppindex 69da76fc6d8..efdb0d58748 100644--- a/Libraries/LibWeb/ServiceWorker/Cache.cpp+++ b/Libraries/LibWeb/ServiceWorker/Cache.cpp@@ -30,7 +30,7 @@ namespace Web::ServiceWorker {GC_DEFINE_ALLOCATOR(Cache);GC_DEFINE_ALLOCATOR(CacheBatchOperation);-static void resolve_cache_response_list(JS::Realm& realm, WebIDL::Promise& promise, GC::Ref<GC::HeapVector<GC::Ref<Fetch::Infrastructure::Response>>> responses)+static void resolve_cache_response_list(JS::Realm& realm, WebIDL::Promise& promise, GC::Ref<GC::HeapVector<GC::Ref<Fetch::Infrastructure::ResponseView>>> responses){auto response_list = GC::Heap::the().allocate<GC::HeapVector<JS::Value>>();@@ -156,7 +156,7 @@ void Cache::match_all(JS::Realm& realm, Optional<Fetch::RequestInfo> request, Ca// 5. Run these substeps in parallel:Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [this, &realm, inner_request, promise, request = move(request), options]() {// 1. Let responses be an empty list.- auto responses = GC::Heap::the().allocate<GC::HeapVector<GC::Ref<Fetch::Infrastructure::Response>>>();+ auto responses = GC::Heap::the().allocate<GC::HeapVector<GC::Ref<Fetch::Infrastructure::ResponseView>>>();// 2. If the optional argument request is omitted, then:if (!request.has_value()) {@@ -291,7 +291,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,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) {+ fetch_algorithms_input.process_response = [&realm, fetch_controllers, response_promise](GC::Ref<Fetch::Infrastructure::ResponseView> response) {HTML::TemporaryExecutionContext context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };bool did_reject_promise = false;@@ -371,7 +371,7 @@ void Cache::add_all(JS::Realm& realm, ReadonlySpan<Fetch::RequestInfo> requests,// 3. For each response in responses:for (size_t index = 0; index < responses.indexed_array_like_size(); ++index) {auto response_value = TRY(responses.get(index));- auto& response = as<Fetch::Infrastructure::Response>(response_value.as_cell());+ auto& response = as<Fetch::Infrastructure::ResponseView>(response_value.as_cell());// 1. Let operation be a cache batch operation.auto operation = GC::Heap::the().allocate<CacheBatchOperation>(@@ -751,7 +751,7 @@ void Cache::keys(JS::Realm& realm, Optional<Fetch::RequestInfo> request, CacheQustatic bool request_matches_cached_item(NonnullRefPtr<Fetch::Infrastructure::Request> request_query,NonnullRefPtr<Fetch::Infrastructure::Request> request,- GC::Ptr<Fetch::Infrastructure::Response> response,+ GC::Ptr<Fetch::Infrastructure::ResponseView> response,CacheQueryOptions options){// 1. If options["ignoreMethod"] is false and request’s method is not `GET`, return false.diff --git a/Libraries/LibWeb/ServiceWorker/Cache.h b/Libraries/LibWeb/ServiceWorker/Cache.hindex ef372ab522f..05791f18984 100644--- a/Libraries/LibWeb/ServiceWorker/Cache.h+++ b/Libraries/LibWeb/ServiceWorker/Cache.h@@ -29,7 +29,7 @@ struct CacheBatchOperation : public GC::Cell {Put,};- CacheBatchOperation(Type type, NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::Response> response = {}, CacheQueryOptions options = {})+ CacheBatchOperation(Type type, NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ptr<Fetch::Infrastructure::ResponseView> response = {}, CacheQueryOptions options = {}): type(type), request(request), response(response)@@ -41,7 +41,7 @@ struct CacheBatchOperation : public GC::Cell {Type type;NonnullRefPtr<Fetch::Infrastructure::Request> request;- GC::Ptr<Fetch::Infrastructure::Response> response;+ GC::Ptr<Fetch::Infrastructure::ResponseView> response;CacheQueryOptions options;};diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cppindex 5b4f40c5d86..a61faef6aab 100644--- a/Libraries/LibWeb/ServiceWorker/Job.cpp+++ b/Libraries/LibWeb/ServiceWorker/Job.cpp@@ -159,7 +159,7 @@ public:return GC::Heap::the().allocate<UpdateAlgorithmState>();}- OrderedHashMap<URL::URL, GC::Ref<Fetch::Infrastructure::Response>>& updated_resource_map() { return m_map; }+ OrderedHashMap<URL::URL, GC::Ref<Fetch::Infrastructure::ResponseView>>& updated_resource_map() { return m_map; }bool has_updated_resources() const { return m_has_updated_resources; }void set_has_updated_resources(bool b) { m_has_updated_resources = b; }@@ -172,7 +172,7 @@ private:visitor.visit(m_map);}- OrderedHashMap<URL::URL, GC::Ref<Fetch::Infrastructure::Response>> m_map;+ OrderedHashMap<URL::URL, GC::Ref<Fetch::Infrastructure::ResponseView>> m_map;bool m_has_updated_resources { false };};@@ -258,7 +258,7 @@ static void update(JS::VM& vm, GC::Ref<Job> job)// Is this actually what the spec wants us to do?IGNORE_USE_IN_ESCAPING_LAMBDA auto process_response_completion_result = Optional<WebIDL::ExceptionOr<void>> {};- fetch_algorithms_input.process_response = [request, job, state, newest_worker, ®istration, &process_response_completion_result](GC::Ref<Fetch::Infrastructure::Response> response) mutable -> void {+ fetch_algorithms_input.process_response = [request, job, state, newest_worker, ®istration, &process_response_completion_result](GC::Ref<Fetch::Infrastructure::ResponseView> response) mutable -> void {// 7. Extract a MIME type from the response’s header list. If s MIME type (ignoring parameters) is not a JavaScript MIME type, then:auto mime_type = Fetch::Infrastructure::extract_mime_type(response->header_list());if (!mime_type.has_value() || !mime_type->is_javascript()) {diff --git a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cppindex 46ad9ed9c7e..628565d8532 100644--- a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp+++ b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.cpp@@ -5,14 +5,14 @@*/#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/ServiceWorker/NameToCacheMap.h>namespace Web::ServiceWorker {GC_DEFINE_ALLOCATOR(RequestResponse);-RequestResponse::RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ref<Fetch::Infrastructure::Response> response)+RequestResponse::RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request> request, GC::Ref<Fetch::Infrastructure::ResponseView> response): request(move(request)), response(response){diff --git a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.hindex f9cc30d26c0..797c664bf1f 100644--- a/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h+++ b/Libraries/LibWeb/ServiceWorker/NameToCacheMap.h@@ -19,12 +19,12 @@ struct RequestResponse : public GC::Cell {GC_CELL(RequestResponse, GC::Cell);GC_DECLARE_ALLOCATOR(RequestResponse);- RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request>, GC::Ref<Fetch::Infrastructure::Response>);+ RequestResponse(NonnullRefPtr<Fetch::Infrastructure::Request>, GC::Ref<Fetch::Infrastructure::ResponseView>);virtual void visit_edges(Visitor&) override;NonnullRefPtr<Fetch::Infrastructure::Request> request;- GC::Ref<Fetch::Infrastructure::Response> response;+ GC::Ref<Fetch::Infrastructure::ResponseView> response;};// https://w3c.github.io/ServiceWorker/#dfn-request-response-listdiff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cppindex e97f1069cba..0ede8501761 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp@@ -41,7 +41,7 @@#include <LibWeb/Fetch/Infrastructure/HTTP.h>#include <LibWeb/Fetch/Infrastructure/HTTP/MIME.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/FileAPI/Blob.h>#include <LibWeb/HTML/EventHandler.h>#include <LibWeb/HTML/EventLoop/EventLoop.h>@@ -89,7 +89,7 @@ GC::Ref<XMLHttpRequest> XMLHttpRequest::create(GC::Ref<DOM::EventTarget> relevan{auto upload_object = GC::Heap::the().allocate<XMLHttpRequestUpload>();auto author_request_headers = HTTP::HeaderList::create();- auto response = Fetch::Infrastructure::Response::network_error("Not sent yet"_string);+ auto response = Fetch::Infrastructure::ResponseView::network_error("Not sent yet"_string);auto fetch_controller = Fetch::Infrastructure::FetchController::create();auto xhr = GC::Heap::the().allocate<XMLHttpRequest>(relevant_global_object, *upload_object, move(author_request_headers), *response, *fetch_controller);live_xml_http_requests().append(xhr);@@ -109,7 +109,7 @@ WebIDL::ExceptionOr<GC::Ref<XMLHttpRequest>> XMLHttpRequest::create_for_construcreturn XMLHttpRequest::create(global_scope->this_impl());}-XMLHttpRequest::XMLHttpRequest(GC::Ref<DOM::EventTarget> relevant_global_object, XMLHttpRequestUpload& upload_object, NonnullRefPtr<HTTP::HeaderList> author_request_headers, Fetch::Infrastructure::Response& response, Fetch::Infrastructure::FetchController& fetch_controller)+XMLHttpRequest::XMLHttpRequest(GC::Ref<DOM::EventTarget> relevant_global_object, XMLHttpRequestUpload& upload_object, NonnullRefPtr<HTTP::HeaderList> author_request_headers, Fetch::Infrastructure::ResponseView& response, Fetch::Infrastructure::FetchController& fetch_controller): XMLHttpRequestEventTarget(), m_upload_object(upload_object), m_global_object(relevant_global_object)@@ -684,7 +684,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method, Utf16String// Unset this’s upload listener flag.m_upload_listener = false;// Set this’s response to a network error.- m_response = Fetch::Infrastructure::Response::network_error("Not yet sent"_string);+ m_response = Fetch::Infrastructure::ResponseView::network_error("Not yet sent"_string);// Set this’s received bytes to the empty byte sequence.m_received_bytes = {};// Set this’s response object to null.@@ -958,7 +958,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB// 9. Let processResponse, given a response, be these steps:// NOTE: `this` is kept alive by FetchAlgorithms using GC::HeapFunction.- auto process_response = [this](GC::Ref<Fetch::Infrastructure::Response> response) {+ auto process_response = [this](GC::Ref<Fetch::Infrastructure::ResponseView> response) {// 1. Set this’s response to response.m_response = response;@@ -1035,7 +1035,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB// 12. Let processBodyError be these steps:auto process_body_error = GC::create_function(GC::Heap::the(), [this](JS::Value) {// 1. Set this’s response to a network error.- m_response = Fetch::Infrastructure::Response::network_error("A network error occurred processing body."_string);+ m_response = Fetch::Infrastructure::ResponseView::network_error("A network error occurred processing body."_string);// 2. Run handle errors for this.// NOTE: This cannot throw, as `handle_errors` only throws in a synchronous context.MUST(handle_errors());@@ -1059,7 +1059,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestBHTML::queue_global_task(HTML::Task::Source::Networking, relevant_global_object(), GC::create_function(heap(), [this, fetch_controller] {if (m_fetch_controller != fetch_controller)return;- m_response = Fetch::Infrastructure::Response::aborted_network_error();+ m_response = Fetch::Infrastructure::ResponseView::aborted_network_error();MUST(handle_errors());}));}));@@ -1082,7 +1082,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestBauto did_time_out = Fetch::Fetching::RefCountedFlag::create(false);// 2. Let processResponseConsumeBody, given a response and nullOrFailureOrBytes, be these steps:- auto process_response_consume_body = [this, processed_response, did_time_out](GC::Ref<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes null_or_failure_or_bytes) {+ auto process_response_consume_body = [this, processed_response, did_time_out](GC::Ref<Fetch::Infrastructure::ResponseView> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes null_or_failure_or_bytes) {// AD-HOC: Leave this's response and received bytes alone once send() returned for a timeout.if (did_time_out->value())return;@@ -1298,7 +1298,7 @@ void XMLHttpRequest::abort()// Spec Note: No readystatechange event is dispatched.if (m_state == State::Done) {m_state = State::Unsent;- m_response = Fetch::Infrastructure::Response::network_error("Not yet sent"_string);+ m_response = Fetch::Infrastructure::ResponseView::network_error("Not yet sent"_string);update_activity_root();}}@@ -1410,7 +1410,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::request_error_steps(Utf16FlyString conupdate_activity_root();// 3. Set xhr’s response to a network error.- m_response = Fetch::Infrastructure::Response::network_error("Failed to load"_string);+ m_response = Fetch::Infrastructure::ResponseView::network_error("Failed to load"_string);// 4. If xhr’s synchronous flag is set, then throw exception.if (m_synchronous) {diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Libraries/LibWeb/XHR/XMLHttpRequest.hindex 3dd7742e1cf..957e2cf62d0 100644--- a/Libraries/LibWeb/XHR/XMLHttpRequest.h+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.h@@ -135,7 +135,7 @@ private:bool should_be_kept_alive() const;void update_activity_root();- XMLHttpRequest(GC::Ref<DOM::EventTarget> relevant_global_object, XMLHttpRequestUpload&, NonnullRefPtr<HTTP::HeaderList>, Fetch::Infrastructure::Response&, Fetch::Infrastructure::FetchController&);+ XMLHttpRequest(GC::Ref<DOM::EventTarget> relevant_global_object, XMLHttpRequestUpload&, NonnullRefPtr<HTTP::HeaderList>, Fetch::Infrastructure::ResponseView&, Fetch::Infrastructure::FetchController&);// https://xhr.spec.whatwg.org/#upload-object// upload object@@ -206,7 +206,7 @@ private:// https://xhr.spec.whatwg.org/#response// response// A response, initially a network error.- GC::Ref<Fetch::Infrastructure::Response> m_response;+ GC::Ref<Fetch::Infrastructure::ResponseView> m_response;// https://xhr.spec.whatwg.org/#received-bytes// received bytesdiff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.pyindex b0d3e710c13..19899c7fda4 100755--- a/Meta/Linters/check_libweb_realm_mentions.py+++ b/Meta/Linters/check_libweb_realm_mentions.py@@ -43,9 +43,9 @@ ALLOWED_REALM_MENTIONS = {"Crypto": (8, 382, "WebCrypto algorithms still use realms for buffer/key/promise materialization"),"DOM": (10, 33, "DOM abort plumbing and node helpers still have callback/materialization realm use"),"Fetch": (- 20,- 55,- "Fetch bodies, headers, requests, responses, and controllers still materialize JS values/streams; "+ 22,+ 57,+ "Fetch bodies, headers, requests, responses, response views, and controllers still materialize JS values/streams; ""BodyStreamPullSource materializes stream pulls and errors on the consumer side, in its stream's realm",),"FileAPI": (4, 11, "File/Blob/FileReader algorithms still create streams, buffers, and events in selected realms"),diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cppindex e6f74409bb9..134e8297e90 100644--- a/Services/WebWorker/WorkerHost.cpp+++ b/Services/WebWorker/WorkerHost.cpp@@ -15,7 +15,7 @@#include <LibWeb/Fetch/Fetching/ClientContextSnapshots.h>#include <LibWeb/Fetch/Fetching/Fetching.h>#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/DedicatedWorkerGlobalScope.h>#include <LibWeb/HTML/MessageEvent.h>#include <LibWeb/HTML/MessagePort.h>@@ -182,7 +182,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes// 4. If the Run CSP initialization for a global object algorithm returns "Blocked" when executed upon// worker global scope, set response to a network error. [CSP]if (worker_global_scope->run_csp_initialization() == Web::ContentSecurityPolicy::Directives::Directive::Result::Blocked) {- response = Web::Fetch::Infrastructure::Response::network_error("Blocked by Content Security Policy"_string);+ response = Web::Fetch::Infrastructure::ResponseView::network_error("Blocked by Content Security Policy"_string);}// 5. If worker global scope's embedder policy's value is compatible with cross-origin isolation and is@@ -197,7 +197,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes// 6. If the result of checking a global object's embedder policy with worker global scope, outside settings,// and response is false, then set response to a network error.if (!worker_global_scope->check_embedder_policy(outside_settings->settings.policy_container.embedder_policy))- response = Web::Fetch::Infrastructure::Response::network_error("Blocked by Cross-Origin-Embedder-Policy"_string);+ response = Web::Fetch::Infrastructure::ResponseView::network_error("Blocked by Cross-Origin-Embedder-Policy"_string);// 7. Set worker global scope's cross-origin isolated capability to true if agent's agent cluster's// cross-origin isolation mode is "concrete".diff --git a/Tests/LibWeb/TestDownloadReader.cpp b/Tests/LibWeb/TestDownloadReader.cppindex 2a959d89adc..418ee09a084 100644--- a/Tests/LibWeb/TestDownloadReader.cpp+++ b/Tests/LibWeb/TestDownloadReader.cpp@@ -8,7 +8,7 @@#include <LibWeb/Bindings/MainThreadVM.h>#include <LibWeb/Bindings/PrincipalHostDefined.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>-#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>+#include <LibWeb/Fetch/Infrastructure/HTTP/ResponseView.h>#include <LibWeb/HTML/LocalTraversableNavigable.h>#include <LibWeb/Page/Page.h>#include <LibWeb/Platform/FontPlugin.h>@@ -85,7 +85,7 @@ TEST_CASE(download_reader_is_registered_with_page_client)auto response = Web::Fetch::Infrastructure::Response::create(vm);response->set_body(Web::Fetch::Infrastructure::byte_sequence_as_body(*realm, "download contents"sv.bytes()));- traversable->handle_as_a_download(response, URL::about_blank(), nullptr, "download.txt", {});+ traversable->handle_as_a_download(Web::Fetch::Infrastructure::ResponseView::create(response), URL::about_blank(), nullptr, "download.txt", {});EXPECT(client->m_registered_download_id.has_value());if (!client->m_registered_download_id.has_value())