LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP

The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP
caching) implementation. We currently have one implementation in LibWeb
for our in-memory cache and another in RequestServer for our disk cache.

The implementations both largely revolve around interacting with HTTP
headers. But in LibWeb, we are using Fetch's header infra, and in RS we
are using are home-grown header infra from LibHTTP.

So to give these a common denominator, this patch replaces the LibHTTP
implementation with Fetch's infra. Our existing LibHTTP implementation
was not particularly compliant with any spec, so this at least gives us
a standards-based common implementation.

This migration also required moving a handful of other Fetch AOs over
to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP
folder, so perhaps it makes sense for LibHTTP to be the implementation
of that entire set of facilities.)
This commit is contained in:
Timothy Flynn 2025-11-26 14:13:23 -05:00 committed by Jelle Raaijmakers
parent 3dce6766a3
commit 9375660b64
Notes: github-actions[bot] 2025-11-27 13:58:52 +00:00
78 changed files with 935 additions and 1017 deletions

View file

@ -13,11 +13,11 @@ namespace RequestServer {
static constexpr u32 CACHE_METADATA_KEY = 12389u;
static ByteString serialize_headers(HTTP::HeaderMap const& headers)
static ByteString serialize_headers(HTTP::HeaderList const& headers)
{
StringBuilder builder;
for (auto const& header : headers.headers()) {
for (auto const& header : headers) {
builder.append(header.name);
builder.append(':');
builder.append(header.value);
@ -27,9 +27,9 @@ static ByteString serialize_headers(HTTP::HeaderMap const& headers)
return builder.to_byte_string();
}
static HTTP::HeaderMap deserialize_headers(StringView serialized_headers)
static NonnullRefPtr<HTTP::HeaderList> deserialize_headers(StringView serialized_headers)
{
HTTP::HeaderMap headers;
auto headers = HTTP::HeaderList::create();
serialized_headers.for_each_split_view('\n', SplitBehavior::Nothing, [&](StringView serialized_header) {
auto index = serialized_header.find(':');
@ -41,7 +41,7 @@ static HTTP::HeaderMap deserialize_headers(StringView serialized_headers)
return;
auto value = serialized_header.substring_view(*index + 1).trim_whitespace();
headers.set(name, value);
headers->append({ name, value });
});
return headers;
@ -110,15 +110,15 @@ CacheIndex::CacheIndex(Database::Database& database, Statements statements)
{
}
void CacheIndex::create_entry(u64 cache_key, String url, HTTP::HeaderMap response_headers, u64 data_size, UnixDateTime request_time, UnixDateTime response_time)
void CacheIndex::create_entry(u64 cache_key, String url, NonnullRefPtr<HTTP::HeaderList> response_headers, u64 data_size, UnixDateTime request_time, UnixDateTime response_time)
{
auto now = UnixDateTime::now();
for (size_t i = 0; i < response_headers.headers().size();) {
auto const& header = response_headers.headers()[i];
for (size_t i = 0; i < response_headers->headers().size();) {
auto const& header = response_headers->headers()[i];
if (is_header_exempted_from_storage(header.name))
response_headers.remove(header.name);
response_headers->delete_(header.name);
else
++i;
}
@ -156,7 +156,7 @@ void CacheIndex::remove_entries_accessed_since(UnixDateTime since, Function<void
since);
}
void CacheIndex::update_response_headers(u64 cache_key, HTTP::HeaderMap response_headers)
void CacheIndex::update_response_headers(u64 cache_key, NonnullRefPtr<HTTP::HeaderList> response_headers)
{
auto entry = m_entries.get(cache_key);
if (!entry.has_value())