Truly independent web browser
LibWeb: Correct what comments say about fetch bodies
Luke Wilde4a5f7123e105
diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cppindex b9ad352e3ce..6b02f5f56a6 100644--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp@@ -210,7 +210,8 @@ void BodyStreamPullSource::on_pull_wake()if (!m_pending_pull_promise)return;- // AD-HOC: While a sync XHR send() pauses the HTML event loop, the pull runs now rather than in a fetch task.+ // AD-HOC: While the HTML event loop is paused, the pull runs now rather than in a fetch task, which would not run+ // until the loop resumes.if (HTML::main_thread_event_loop().execution_paused()) {run_pull_task();push_while_paused();diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.h b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.hindex 1aea4e95bc4..81472573431 100644--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.h+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.h@@ -38,8 +38,8 @@ private:BodyStreamWakeToken const m_registry_token { 0 };};-// The pull algorithm of a response stream whose bytes arrive through a FetchByteChannel. The channel's end reaches the-// stream even when no pull is pending.+// The pull algorithm of a response stream whose bytes arrive through a FetchByteChannel. The channel's error, or its+// close with no bytes left unread, reaches the stream even when no pull is pending.class BodyStreamPullSource final : public JS::Cell {GC_CELL(BodyStreamPullSource, JS::Cell);GC_DECLARE_ALLOCATOR(BodyStreamPullSource);@@ -94,7 +94,7 @@ private:GC::Ptr<GC::Function<void(Core::ImmutableBytes, Infrastructure::Body::SniffOutcome)>> m_on_resource_header;bool m_has_taken_bytes { false };- // Once the channel has ended, later pulls stay pending.+ // Once set, later pulls stay pending until the stream is cancelled.bool m_detached { false };};diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex e62c5fad636..55636f868d0 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -2660,7 +2660,7 @@ struct NetworkBody {}// https://fetch.spec.whatwg.org/#concept-http-network-fetch-// NB: Step 9 of HTTP-network fetch. Steps 10 to 13 run in create_body_from_channel(), where the body is first read.+// NB: Step 9 of HTTP-network fetch. Steps 10 to 13 run in create_body_from_channel(), when the body's view is made.static NetworkBody create_network_body(RefPtr<Infrastructure::FetchParams const> fetch_params, Engine::FetchBodyDeliveryGate::NavigationHold navigation_hold, RefPtr<HTTP::MemoryCache> http_cache){// 9. Let buffer be an empty byte sequence.@@ -2723,7 +2723,7 @@ GC::Ptr<Infrastructure::Body> adopt_navigation_response_body(JS::Realm& realm, Iauto delivery_gate = network_body.delivery_gate;auto network_transport = Engine::NetworkTransportHandle::create(*request);delivery_gate->attach_transport(network_transport);- // A request either finishes or tears down, so the observer hears the body's end once.+ // The observer hears the body's end at most once.auto network_settled = GC::make_root(GC::create_function(GC::Heap::the(), move(on_network_settled)));network_transport->set_on_teardown([delivery_gate, channel, network_settled](Requests::Request::TeardownReason reason) {tear_down_network_body(*delivery_gate, *channel, reason);@@ -2850,8 +2850,8 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(return;}- // AD-HOC: From here on, the response's body delivery is scheduled against the event loop (see- // BodyStreamPullSource::on_wake()); record that, for consume_a_preloaded_resource().+ // AD-HOC: Record that the response has arrived, which consume_a_preloaded_resource() checks before+ // re-targeting this fetch.fetch_params->control_block().set_response_arrived();auto response = Infrastructure::Response::create();@@ -2904,7 +2904,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(body_pump->set_response(response);// 14. Set response’s body to a new body whose stream is stream.- // NB: The stream is made from the channel where the body is first read.+ // NB: The stream is made from the channel when the body's view is made.response->set_body(Infrastructure::ResponseBody { channel, {} });// NB: HTTP-network-or-cache fetch's "Store httpRequest and forwardResponse in httpCache" runs here, as thediff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.h b/Libraries/LibWeb/Fetch/Fetching/Fetching.hindex 0fec644b340..df7ca4da4e9 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.h+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.h@@ -57,7 +57,8 @@ WEB_API GC::Ptr<PendingResponse> http_redirect_fetch(JS::Realm&, Infrastructure:GC::Ref<PendingResponse> http_network_or_cache_fetch(JS::Realm&, Infrastructure::FetchParams const&, IsAuthenticationFetch is_authentication_fetch = IsAuthenticationFetch::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No);GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(JS::Realm&, Infrastructure::FetchParams const&, HTTP::Cookie::IncludeCredentials include_credentials = HTTP::Cookie::IncludeCredentials::No, IsNewConnectionFetch is_new_connection_fetch = IsNewConnectionFetch::No, RefPtr<HTTP::MemoryCache> = {});GC::Ref<PendingResponse> cors_preflight_fetch(JS::Realm&, Infrastructure::FetchParams const&);-// on_network_settled runs once: when the network completes the body, or with an error when the body fails or stops.+// on_network_settled runs at most once: when the network completes the body, or with an error when the body fails+// or is stopped.GC::Ptr<Infrastructure::Body> adopt_navigation_response_body(JS::Realm&, Infrastructure::Response&, Optional<Utf16String> const& request_server_top_level_site, Requests::RequestTransferLeaseKey, RefPtr<Infrastructure::FetchTimingInfo>, Function<void(Optional<StringView> error)> on_network_settled);// Stopping the transport also cancels the channel.WEB_API NonnullRefPtr<Engine::WholeBodyTransport> create_whole_body_transport(Engine::FetchBodyDeliveryGate&, Engine::FetchByteChannel&);diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.hindex 2fcfc385bae..e82c12955ea 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h@@ -56,8 +56,8 @@ public:void report_timing(JS::Object&) const;void process_next_manual_redirect() const;- // Runs the steps once the network has delivered all of the body whose bytes arrive through the channel, in place of- // any steps set before.+ // Runs the steps once the network has delivered all of the body whose bytes arrive through the channel, unless the+ // fetch is aborted, terminated or stopped first. A later call replaces them.void when_network_completes_body(Engine::FetchByteChannel const&, GC::Ref<GC::Function<void()>> steps);void did_complete_network_body(Engine::FetchByteChannel const&);[[nodiscard]] NonnullRefPtr<FetchTimingInfo> extract_full_timing_info() const;diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cppindex 04ab31846b0..212899fc3eb 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp@@ -224,7 +224,7 @@ GC::Ref<Body> byte_sequence_as_body(JS::Realm& realm, ReadonlyBytes bytes)}// https://fetch.spec.whatwg.org/#byte-sequence-as-a-body-// NB: The body's stream is made from its bytes where the body is first read.+// NB: Each view of the body makes its stream from these bytes.ResponseBody byte_sequence_as_response_body(ReadonlyBytes bytes){return ResponseBody::from_bytes(MUST(Core::ImmutableBytes::copy(bytes)));diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.hindex 4f29ce959ac..17c437666f5 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h@@ -55,7 +55,7 @@ private:// A response's body as fetch keeps it: its length and where its bytes are.class WEB_API ResponseBody {public:- // The bytes are read through a stream outside fetch.+ // The bytes are read through the stream of the response's body view.struct ReadThroughStream { };using Bytes = Variant<Core::ImmutableBytes, NonnullRefPtr<Engine::FetchByteChannel>, ReadThroughStream>;diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.hindex 1e8ef850025..9d845f9a4dd 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h@@ -146,8 +146,8 @@ public:virtual void resume_body_delivery() const;virtual void resume_body_delivery_up_to(size_t) const;- // Stops this process taking the body, whose request another process adopts next, and returns the bytes that- // process reads before the rest.+ // Stops this process taking the body, and returns the bytes that a process adopting its request reads before the+ // rest.virtual Vector<Core::ImmutableBytes> release_body_for_transfer() const;protected:diff --git a/Libraries/LibWeb/Fetch/Request.h b/Libraries/LibWeb/Fetch/Request.hindex 4c5e6f42003..f5f3d2aadea 100644--- a/Libraries/LibWeb/Fetch/Request.h+++ b/Libraries/LibWeb/Fetch/Request.h@@ -80,7 +80,7 @@ private:// A Request object has an associated request (a request).NonnullRefPtr<Infrastructure::Request> m_request;- // The body of this's request, with its stream.+ // The body this object was created with, with its stream.GC::Ptr<Infrastructure::Body> m_body;// https://fetch.spec.whatwg.org/#request-headersdiff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 077c0000670..7d0fcb876d3 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -611,7 +611,7 @@ static bool handle_navigation_response_as_download(GC::Ref<NavigationParams> nav}auto suggested_filename = suggested_download_filename(download_url, *response->header_list(), {}, interface_origin);- // The UI process downloads the bytes this process received from the body first, then the rest of the request.+ // A download the UI process starts reads the bytes released here before the rest of the request.ByteBuffer initial_data;for (auto const& received : response->release_body_for_transfer())initial_data.append(received.bytes());diff --git a/Libraries/LibWeb/HTML/PreloadEntry.cpp b/Libraries/LibWeb/HTML/PreloadEntry.cppindex 3fde9272c55..6c4e2d2d3c7 100644--- a/Libraries/LibWeb/HTML/PreloadEntry.cpp+++ b/Libraries/LibWeb/HTML/PreloadEntry.cpp@@ -93,8 +93,8 @@ bool consume_a_preloaded_resource((void)integrity_metadata;// AD-HOC: A sync XHR consumer, whose event loop is paused while it's blocked, can't park on an in-flight entry whose- // fetch's response has already arrived: Its delivery and processing are already queued against the event- // loop, beyond the reach of step 9's re-targeting, so they can't hand the response over. Return false, so+ // fetch's response has already arrived: Its processing may already be queued against the event loop,+ // beyond the reach of step 9's re-targeting, so it could not hand the response over. Return false, so// the consumer fetches on its own (as Blink/WebKit have every sync request do; see step 9), and leave the// entry in the map: The preload completes once the loop resumes.if (!entry->response && consumer_body_intent == Fetch::Engine::BodyIntent::SyncAccumulate && entry->controller