mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02:00
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:
committed by
Jelle Raaijmakers
parent
884efef99d
commit
9f2ac14521
Notes:
github-actions[bot]
2026-01-08 11:00:23 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/9f2ac14521d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7374 Reviewed-by: https://github.com/gmta ✅
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user