ladybird/Libraries/LibHTTP/Cache/MemoryCache.h
Timothy Flynn 0d99d54c46 LibHTTP+LibWeb: Do not cache range requests (for now)
We currently do not handle responses for range requests at all in our
HTTP caches. This means if we issue a request for a range of bytes=1-10,
that response will be served to a subsequent request for a range of
bytes=10-20. This is obviously invalid - so until we handle these
requests, just don't cache them for now.
2026-01-08 11:59:12 +01:00

41 lines
1.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, HeaderList const& request_headers, 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;
};
}