Files
ladybird/Tests/LibHTTP/TestCacheUtilities.cpp
Praise-Garfield 9b8e341828 LibHTTP: Implement the must-understand cache directive
This implements the must-understand response cache directive per RFC
9111 Section 5.2.2.3. When a response contains must-understand, this
cache now ignores the no-store directive for status codes whose
caching behavior it implements. For status codes the cache does not
understand, the response is not stored.
2026-02-14 14:34:34 -05:00

46 lines
1.5 KiB
C++

/*
* Copyright (c) 2026, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibHTTP/Cache/Utilities.h>
#include <LibHTTP/HeaderList.h>
#include <LibTest/TestCase.h>
TEST_CASE(is_cacheable_must_understand_ignores_no_store_for_understood_status)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "must-understand, no-store, max-age=3600" } });
EXPECT(HTTP::is_cacheable(200, *headers));
}
TEST_CASE(is_cacheable_must_understand_rejects_unknown_status)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "must-understand, no-store, max-age=3600" } });
EXPECT(!HTTP::is_cacheable(202, *headers));
}
TEST_CASE(is_cacheable_no_store_without_must_understand)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "no-store, max-age=3600" } });
EXPECT(!HTTP::is_cacheable(200, *headers));
}
TEST_CASE(is_cacheable_must_understand_without_no_store_understood_status)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "must-understand, max-age=3600" } });
EXPECT(HTTP::is_cacheable(200, *headers));
}
TEST_CASE(is_cacheable_must_understand_without_no_store_unknown_status)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "must-understand, max-age=3600" } });
EXPECT(!HTTP::is_cacheable(299, *headers));
}
TEST_CASE(is_cacheable_must_understand_accepts_304_status)
{
auto headers = HTTP::HeaderList::create({ { "Cache-Control", "must-understand, no-store, max-age=3600" } });
EXPECT(HTTP::is_cacheable(304, *headers));
}