Merge Phase 6 and reconcile offline completion, response capture and contract tests

This commit is contained in:
Jonathan Sykes
2026-10-09 15:12:14 +08:00
62 changed files with 229652 additions and 43 deletions

View File

@@ -600,7 +600,13 @@ async function assetFetch(request, clientId) {
if(state.current.files[path]?.h === h) {
const previousKey=AssetSyncCore.fallback(state.current,state.previous,path);
const previousResponse=previousKey && await cache.match(previousKey);
if(previousResponse && previousResponse.headers.get('X-Asset-Hash')===state.previous.files[path].h) return previousResponse;
if(previousResponse && previousResponse.headers.get('X-Asset-Hash')===state.previous.files[path].h) {
// A stale body returned under a new URL must not poison the browser's
// resource cache either. Its decoded stream has no transport encoding.
const headers=new Headers(previousResponse.headers);headers.set('Cache-Control','no-store');
for(const name of ['Content-Encoding','Content-Length','Transfer-Encoding'])headers.delete(name);
return new Response(previousResponse.body,{status:previousResponse.status,headers});
}
}
try { const r = await fetch(key); if(r.ok && r.headers.get('X-Asset-Hash') !== h) return new Response('Asset version unavailable',{status:409}); if(r.ok && request.method !== 'HEAD') await cache.put(key,r.clone()); return r; } catch { return new Response('Offline',{status:503}); }
}