Store JavaScript bytecode side data in the WebContent HTTP memory cache and replay it when serving cached responses. Also update an already-complete memory-cache entry when asynchronous bytecode cache generation finishes, so the first source-only response does not keep shadowing the disk-cache sidecar during same-process navigations. Keep the HTTP memory-cache backfill keyed with the request headers that populated the memory-cache entry, so Vary responses still receive their generated bytecode sidecar. Add LibHTTP coverage for round-tripping bytecode side data through a memory-cache entry, attaching it after the response body has already been cached, and matching Vary headers during updates. Add LibWeb coverage for preserving the memory-cache request headers when cloning responses.
31 lines
1.2 KiB
C++
31 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibHTTP/HeaderList.h>
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
#include <LibJS/Runtime/VM.h>
|
|
#include <LibTest/TestCase.h>
|
|
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
|
|
|
|
TEST_CASE(javascript_bytecode_cache_memory_cache_request_headers_are_cloned)
|
|
{
|
|
auto vm = JS::VM::create();
|
|
auto root_execution_context = JS::create_simple_execution_context<JS::GlobalObject>(*vm);
|
|
auto& realm = *root_execution_context->realm;
|
|
|
|
auto request_headers = HTTP::HeaderList::create({
|
|
{ "User-Agent"sv, "Ladybird"sv },
|
|
});
|
|
auto response = Web::Fetch::Infrastructure::Response::create(*vm);
|
|
response->set_javascript_bytecode_cache_memory_cache_request_headers(request_headers);
|
|
|
|
auto cloned_response = response->clone(realm);
|
|
auto const& cloned_request_headers = cloned_response->javascript_bytecode_cache_memory_cache_request_headers();
|
|
request_headers->set({ "User-Agent"sv, "Changed"sv });
|
|
|
|
VERIFY(cloned_request_headers.has_value());
|
|
EXPECT_EQ((*cloned_request_headers)->get("User-Agent"sv), Optional<ByteString> { "Ladybird" });
|
|
}
|