diff --git a/packages/pages-shared/__tests__/asset-server/handler.test.ts b/packages/pages-shared/__tests__/asset-server/handler.test.ts index 1bf81649f306..56e47b62d4a3 100644 --- a/packages/pages-shared/__tests__/asset-server/handler.test.ts +++ b/packages/pages-shared/__tests__/asset-server/handler.test.ts @@ -592,6 +592,7 @@ describe("asset-server handler", () => { "cache-control": "public, s-maxage=604800", "x-robots-tag": "noindex", "cf-cache-status": "HIT", // new header + "x-cf-pgs-apc": "HIT", // new header }); // Serve with a fresh cache and ensure we don't get a response diff --git a/packages/pages-shared/asset-server/handler.ts b/packages/pages-shared/asset-server/handler.ts index 603abaa48207..338b944f7fd0 100644 --- a/packages/pages-shared/asset-server/handler.ts +++ b/packages/pages-shared/asset-server/handler.ts @@ -29,6 +29,11 @@ export const ASSET_PRESERVATION_CACHE_V1 = "assetPreservationCache"; // V2 stores the content hash instead of the asset. // TODO: Remove V1 once we've fully migrated to V2 export const ASSET_PRESERVATION_CACHE_V2 = "assetPreservationCacheV2"; +/** + * Response header will be present w/ "HIT" + * value if served from `ASSET_PRESERVATION_CACHE_V2` + */ +const HEADER_ASSET_PRESERVATION_CACHE_V2 = "x-cf-pgs-apc"; const CACHE_CONTROL_PRESERVATION = "public, s-maxage=604800"; // 1 week /** The preservation cache should be periodically @@ -676,7 +681,9 @@ export async function generateHandler< const asset = await fetchAsset(assetKey); if (asset) { // We know the asset hasn't changed, so use the cached headers. - return new Response(asset.body, preservedResponse); + const response = new Response(asset.body, preservedResponse); + response.headers.set(HEADER_ASSET_PRESERVATION_CACHE_V2, "HIT"); + return response; } else { logError( new Error(