@@ -286,10 +286,20 @@ async function processResourceRequest(
286
286
return requestTimeout ( ) ;
287
287
}
288
288
289
+ /** @type {Record<string, string> } */
290
+ const accessControlHeaders = {
291
+ 'Access-Control-Allow-Origin' : '*' ,
292
+ 'Cross-Origin-Resource-Policy' : 'cross-origin' ,
293
+ } ;
294
+
289
295
const entry = result . value ;
290
296
if ( entry . status === 304 ) { // Not modified
291
297
if ( cachedResponse ) {
292
- return cachedResponse . clone ( ) ;
298
+ const r = cachedResponse . clone ( ) ;
299
+ for ( const [ key , value ] of Object . entries ( accessControlHeaders ) ) {
300
+ r . headers . set ( key , value ) ;
301
+ }
302
+ return r ;
293
303
} else {
294
304
throw new Error ( 'No cache found' ) ;
295
305
}
@@ -303,11 +313,6 @@ async function processResourceRequest(
303
313
return notFound ( ) ;
304
314
}
305
315
306
- /** @type {Record<string, string> } */
307
- const commonHeaders = {
308
- 'Access-Control-Allow-Origin' : '*' ,
309
- } ;
310
-
311
316
const byteLength = entry . data . byteLength ;
312
317
313
318
const range = event . request . headers . get ( 'range' ) ;
@@ -323,7 +328,7 @@ async function processResourceRequest(
323
328
return new Response ( entry . data . slice ( start , end + 1 ) , {
324
329
status : 206 ,
325
330
headers : {
326
- ...commonHeaders ,
331
+ ...accessControlHeaders ,
327
332
'Content-range' : `bytes 0-${ end } /${ byteLength } ` ,
328
333
}
329
334
} ) ;
@@ -332,7 +337,7 @@ async function processResourceRequest(
332
337
return new Response ( null , {
333
338
status : 416 ,
334
339
headers : {
335
- ...commonHeaders ,
340
+ ...accessControlHeaders ,
336
341
'Content-range' : `*/${ byteLength } `
337
342
}
338
343
} ) ;
@@ -341,7 +346,7 @@ async function processResourceRequest(
341
346
342
347
/** @type {Record<string, string> } */
343
348
const headers = {
344
- ...commonHeaders ,
349
+ ...accessControlHeaders ,
345
350
'Content-Type' : entry . mime ,
346
351
'Content-Length' : byteLength . toString ( ) ,
347
352
} ;
0 commit comments