Skip to content

Commit 9691724

Browse files
Restrict cache-status hit to cases where the cache was actually hit (#30)
1 parent 3fae3d2 commit 9691724

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fetch-filecache.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async function cacheFetch(url, options) {
389389
}
390390
}
391391

392-
async function readFromCache() {
392+
async function readFromCache(hit = false) {
393393
let data = await fs.promises.readFile(cacheHeadersFilename, 'utf8');
394394
let headers = JSON.parse(data);
395395
let status = headers.status || 200;
@@ -409,9 +409,11 @@ async function cacheFetch(url, options) {
409409
return new Response(null, { url, status: 304, headers });
410410
}
411411
let readable = fs.createReadStream(cacheFilename);
412-
// Indicate this is coming from the cache via
413-
// https://www.rfc-editor.org/rfc/rfc9211.html
414-
headers["cache-status"] = "fetch-filecache-for-crawling; hit";
412+
if (hit) {
413+
// Indicate this is coming from the cache via
414+
// https://www.rfc-editor.org/rfc/rfc9211.html
415+
headers["cache-status"] = "fetch-filecache-for-crawling; hit";
416+
}
415417
return new Response(readable, { url, status, headers });
416418
}
417419

@@ -532,7 +534,7 @@ async function cacheFetch(url, options) {
532534
}
533535
else {
534536
resolvePendingFetch();
535-
return readFromCache();
537+
return readFromCache(true);
536538
}
537539
}
538540
catch (err) {

0 commit comments

Comments
 (0)