mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
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.
41 lines
1 KiB
C++
41 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteString.h>
|
|
#include <AK/HashMap.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/RefCounted.h>
|
|
#include <AK/String.h>
|
|
#include <LibHTTP/Forward.h>
|
|
#include <LibURL/URL.h>
|
|
|
|
namespace HTTP {
|
|
|
|
class MemoryCache : public RefCounted<MemoryCache> {
|
|
public:
|
|
struct Entry {
|
|
u32 status_code { 0 };
|
|
ByteString reason_phrase;
|
|
|
|
NonnullRefPtr<HeaderList> response_headers;
|
|
ByteBuffer response_body;
|
|
};
|
|
|
|
static NonnullRefPtr<MemoryCache> create();
|
|
|
|
Optional<Entry const&> open_entry(URL::URL const&, StringView method, HeaderList const& request_headers) const;
|
|
|
|
void create_entry(URL::URL const&, StringView method, u32 status_code, ByteString reason_phrase, HeaderList const& response_headers);
|
|
void finalize_entry(URL::URL const&, StringView method, ByteBuffer response_body);
|
|
|
|
private:
|
|
HashMap<u64, Entry> m_pending_entries;
|
|
HashMap<u64, Entry> m_complete_entries;
|
|
};
|
|
|
|
}
|