ladybird/Libraries/LibHTTP/Cache/CacheMode.h
Timothy Flynn aa1517b727 LibHTTP+LibWeb+RequestServer: Handle the Fetch API's cache mode
If the cache mode is no-store, we must not interact with the cache at
all.

If the cache mode is reload, we must not use any cached response.

If the cache-mode is only-if-cached or force-cache, we are permitted
to respond with stale cache responses.

Note that we currently cannot test only-if-cached in test-web. Setting
this mode also requires setting the cors mode to same-origin, but our
http-test-server infra requires setting the cors mode to cors.
2026-01-22 07:05:06 -05:00

38 lines
1.1 KiB
C++

/*
* Copyright (c) 2026, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
namespace HTTP {
enum class CacheMode : u8 {
// The cache is searched for a matching response. The cache is updated with the server's response.
Default,
// The cache is not searched for a matching response. The cache is not updated with the server's response.
NoStore,
// The cache is not searched for a matching response. The cache is updated with the server's response.
Reload,
// The cache is searched for a matching response, but must always revalidate. The cache is updated with the server's response.
NoCache,
// The cache is searched for a matching fresh or stale response. The cache is updated with the server's response.
ForceCache,
// The cache is searched for a matching fresh or stale response. A cache miss results in a network error.
OnlyIfCached,
};
constexpr bool cache_mode_permits_stale_responses(CacheMode cache_mode)
{
return cache_mode == CacheMode::ForceCache || cache_mode == CacheMode::OnlyIfCached;
}
}