LibHTTP+RequestServer: Do not flush partial responses to the cache index

If the cURL request completes with anything other than CURLE_OK, we must
not keep the cache entry. For example, if the server's connection closes
while transferring data, we receive CURLE_PARTIAL_FILE. We don't want
this cache entry to be treated as valid in a subsequent request.
This commit is contained in:
Timothy Flynn
2026-01-07 21:49:37 -05:00
committed by Jelle Raaijmakers
parent 884efef99d
commit 9f2ac14521
Notes: github-actions[bot] 2026-01-08 11:00:23 +00:00
5 changed files with 57 additions and 0 deletions

View File

@@ -8,11 +8,13 @@
const TEST_CACHE_REQUEST_TIME_OFFSET = "X-Ladybird-Request-Time-Offset";
// http-test-server custom headers.
const TEST_CACHE_RESPOND_WITH_INCOMPLETE_RESPONSE = "X-Ladybird-Respond-With-Incomplete-Response";
const TEST_CACHE_RESPOND_WITH_NOT_MODIFIED = "X-Ladybird-Respond-With-Not-Modified";
const ACCESS_CONTROL_ALLOW_HEADERS = [
TEST_CACHE_ENABLED_HEADER,
TEST_CACHE_REQUEST_TIME_OFFSET,
TEST_CACHE_RESPOND_WITH_INCOMPLETE_RESPONSE,
TEST_CACHE_RESPOND_WITH_NOT_MODIFIED,
].join(", ");
@@ -178,6 +180,34 @@
expectCacheStatus(url, response, "not-cached");
})();
// Incomplete responses are not cached.
await (async () => {
url = await createRequest(`/cache-test/incomplete`, {
headers: {
"Cache-Control": "max-age=999",
},
});
response = await cacheFetch(url, {
headers: {
[TEST_CACHE_RESPOND_WITH_INCOMPLETE_RESPONSE]: "1",
},
});
try {
await response.text();
println(`Expected ${url} to result in an error while reading the response body`);
anyTestFailed = true;
} catch (e) {}
response = await cacheFetch(url);
expectCacheStatus(url, response, "written-to-cache");
response = await cacheFetch(url);
expectCacheStatus(url, response, "read-from-cache");
})();
// Expired responses are cached until their max-age directive is reached.
await (async () => {
url = await createRequest("/cache-test/expired-and-refreshed", {