mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
RequestServer: Add a hook to advance a request's clock time for testing
For example, we will want to be able to test that a cached object was expired after N seconds. Rather than waiting that time during testing, this adds a testing-only request header to internally advance the clock for a single HTTP request.
This commit is contained in:
parent
b2c112c41a
commit
4de3f77d37
Notes:
github-actions[bot]
2025-11-20 08:35:34 +00:00
Author: https://github.com/trflynn89
Commit: 4de3f77d37
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6861
Reviewed-by: https://github.com/gmta ✅
7 changed files with 50 additions and 22 deletions
|
|
@ -53,7 +53,7 @@ Variant<Optional<CacheEntryWriter&>, DiskCache::CacheHasOpenEntry> DiskCache::cr
|
|||
if (check_if_cache_has_open_entry(request, cache_key, CheckReaderEntries::Yes))
|
||||
return CacheHasOpenEntry {};
|
||||
|
||||
auto cache_entry = CacheEntryWriter::create(*this, m_index, cache_key, move(serialized_url), request.request_start_time());
|
||||
auto cache_entry = CacheEntryWriter::create(*this, m_index, cache_key, move(serialized_url), request.request_start_time(), request.current_time_offset_for_testing());
|
||||
if (cache_entry.is_error()) {
|
||||
dbgln("\033[31;1mUnable to create cache entry for\033[0m {}: {}", request.url(), cache_entry.error());
|
||||
return Optional<CacheEntryWriter&> {};
|
||||
|
|
@ -93,8 +93,8 @@ Variant<Optional<CacheEntryReader&>, DiskCache::CacheHasOpenEntry> DiskCache::op
|
|||
}
|
||||
|
||||
auto const& response_headers = cache_entry.value()->response_headers();
|
||||
auto freshness_lifetime = calculate_freshness_lifetime(cache_entry.value()->status_code(), response_headers);
|
||||
auto current_age = calculate_age(response_headers, index_entry->request_time, index_entry->response_time);
|
||||
auto freshness_lifetime = calculate_freshness_lifetime(cache_entry.value()->status_code(), response_headers, request.current_time_offset_for_testing());
|
||||
auto current_age = calculate_age(response_headers, index_entry->request_time, index_entry->response_time, request.current_time_offset_for_testing());
|
||||
|
||||
switch (cache_lifetime_status(response_headers, freshness_lifetime, current_age)) {
|
||||
case CacheLifetimeStatus::Fresh:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue