LibHTTP+LibWeb: Store the in-memory HTTP cache without JS realms

The in-memory HTTP Fetch cache currently keeps the realm which created
each cache entry alive indefinitely. This patch migrates this cache to
LibHTTP, to ensure it is completely unaware of any JS objects.

Now that we are not interacting with Fetch response objects, we can no
longer use Streams infrastructure to pipe the response body into the
Fetch response. Fetch also ultimately creates the cache response once
the HTTP response headers have arrived. So the LibHTTP cache will hold
entries in a pending list until we have received the entire response
body. Then it is moved to a completed list and may be used thereafter.
This commit is contained in:
Timothy Flynn
2025-12-21 08:58:55 -05:00
committed by Andreas Kling
parent d08bd14928
commit bf7b812d0b
Notes: github-actions[bot] 2025-12-21 15:00:28 +00:00
8 changed files with 212 additions and 108 deletions

View File

@@ -6,6 +6,7 @@
*/
#include <LibGC/Function.h>
#include <LibHTTP/Cache/MemoryCache.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Fetch/Fetching/FetchedDataReceiver.h>
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
@@ -19,9 +20,10 @@ namespace Web::Fetch::Fetching {
GC_DEFINE_ALLOCATOR(FetchedDataReceiver);
FetchedDataReceiver::FetchedDataReceiver(GC::Ref<Infrastructure::FetchParams const> fetch_params, GC::Ref<Streams::ReadableStream> stream)
FetchedDataReceiver::FetchedDataReceiver(GC::Ref<Infrastructure::FetchParams const> fetch_params, GC::Ref<Streams::ReadableStream> stream, RefPtr<HTTP::MemoryCache> http_cache)
: m_fetch_params(fetch_params)
, m_stream(stream)
, m_http_cache(move(http_cache))
{
}
@@ -154,6 +156,11 @@ void FetchedDataReceiver::close_stream()
m_pending_promise = {};
m_lifecycle_state = LifecycleState::Closed;
m_stream->close();
if (m_http_cache) {
m_http_cache->finalize_entry(m_fetch_params->request()->current_url(), m_fetch_params->request()->method(), move(m_buffer));
m_http_cache.clear();
}
}
ByteBuffer FetchedDataReceiver::copy_unpulled_bytes()