From 3913e9f9486bb7f3c223158baea84b53ea2c9535 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 26 Dec 2024 14:58:27 +1300 Subject: [PATCH] LibWeb/Fetch: Return a cloned cached response body Otherwise we will fully read from the cached response and invalidate it's stream, invalidating it for the next time it is read from. Fixes a crash when reloading linegoup.lol after two reloads. --- Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 40fac6b051ee..463e6fa3bac0 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1351,7 +1351,7 @@ WebIDL::ExceptionOr> http_redirect_fetch(JS::Realm& rea class CachePartition : public RefCounted { public: // https://httpwg.org/specs/rfc9111.html#constructing.responses.from.caches - GC::Ptr select_response(URL::URL const& url, ReadonlyBytes method, Vector const& headers, Vector>& initial_set_of_stored_responses) const + GC::Ptr select_response(JS::Realm& realm, URL::URL const& url, ReadonlyBytes method, Vector const& headers, Vector>& initial_set_of_stored_responses) const { // When presented with a request, a cache MUST NOT reuse a stored response unless: @@ -1383,7 +1383,7 @@ class CachePartition : public RefCounted { dbgln("\033[32;1mHTTP CACHE HIT!\033[0m {}", url); - return cached_response.ptr(); + return cached_response->clone(realm); } void store_response(JS::Realm& realm, Infrastructure::Request const& http_request, Infrastructure::Response const& response) @@ -1939,7 +1939,7 @@ WebIDL::ExceptionOr> http_network_or_cache_fetch(JS::Re // validation, as per the "Constructing Responses from Caches" chapter of HTTP Caching [HTTP-CACHING], // if any. // NOTE: As mandated by HTTP, this still takes the `Vary` header into account. - stored_response = http_cache->select_response(http_request->current_url(), http_request->method(), *http_request->header_list(), initial_set_of_stored_responses); + stored_response = http_cache->select_response(realm, http_request->current_url(), http_request->method(), *http_request->header_list(), initial_set_of_stored_responses); // 2. If storedResponse is non-null, then: if (stored_response) { // 1. If cache mode is "default", storedResponse is a stale-while-revalidate response,