2025-12-21 08:58:55 -05:00
|
|
|
/*
|
2026-01-20 17:12:36 -05:00
|
|
|
* Copyright (c) 2025-2026, Tim Flynn <trflynn89@ladybird.org>
|
2025-12-21 08:58:55 -05:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/ByteString.h>
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
|
#include <AK/RefCounted.h>
|
2026-01-11 08:59:30 -05:00
|
|
|
#include <AK/Time.h>
|
2026-01-20 17:12:36 -05:00
|
|
|
#include <LibHTTP/Cache/CacheMode.h>
|
2025-12-21 08:58:55 -05:00
|
|
|
#include <LibHTTP/Forward.h>
|
|
|
|
|
#include <LibURL/URL.h>
|
|
|
|
|
|
|
|
|
|
namespace HTTP {
|
|
|
|
|
|
|
|
|
|
class MemoryCache : public RefCounted<MemoryCache> {
|
|
|
|
|
public:
|
|
|
|
|
struct Entry {
|
2025-12-28 10:23:56 -05:00
|
|
|
u64 vary_key { 0 };
|
|
|
|
|
|
2025-12-21 08:58:55 -05:00
|
|
|
u32 status_code { 0 };
|
|
|
|
|
ByteString reason_phrase;
|
2025-12-24 11:08:14 -05:00
|
|
|
NonnullRefPtr<HeaderList> request_headers;
|
2025-12-21 08:58:55 -05:00
|
|
|
NonnullRefPtr<HeaderList> response_headers;
|
|
|
|
|
ByteBuffer response_body;
|
2026-01-11 08:59:30 -05:00
|
|
|
|
|
|
|
|
UnixDateTime request_time;
|
|
|
|
|
UnixDateTime response_time;
|
2025-12-21 08:58:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static NonnullRefPtr<MemoryCache> create();
|
|
|
|
|
|
2026-01-20 17:12:36 -05:00
|
|
|
Optional<Entry const&> open_entry(URL::URL const&, StringView method, HeaderList const& request_headers, CacheMode);
|
2025-12-21 08:58:55 -05:00
|
|
|
|
2026-01-11 08:59:30 -05:00
|
|
|
void create_entry(URL::URL const&, StringView method, HeaderList const& request_headers, UnixDateTime request_time, u32 status_code, ByteString reason_phrase, HeaderList const& response_headers);
|
2025-12-28 10:23:56 -05:00
|
|
|
void finalize_entry(URL::URL const&, StringView method, HeaderList const& request_headers, u32 status_code, HeaderList const& response_headers, ByteBuffer response_body);
|
2025-12-21 08:58:55 -05:00
|
|
|
|
|
|
|
|
private:
|
2026-02-24 08:03:52 -05:00
|
|
|
HashMap<u64, Vector<Entry>, IdentityHashTraits<u64>> m_pending_entries;
|
|
|
|
|
HashMap<u64, Vector<Entry>, IdentityHashTraits<u64>> m_complete_entries;
|
2025-12-21 08:58:55 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|