fix(serviceworker): Improve cache handling and response header management in service worker.
This commit is contained in:
@@ -124,7 +124,7 @@ export class CacheManager {
|
||||
});
|
||||
|
||||
// If the response status is an error or the response is opaque, do not cache it.
|
||||
if (newResponse.status > 299 || newResponse.type === 'opaque') {
|
||||
if (newResponse.status > 299 || newResponse.type === 'opaque' || (newResponse.headers.get('access-control-allow-origin') === null && !matchRequest.url.startsWith(this.losslessServiceWorkerRef.serviceWindowRef.location.origin))) {
|
||||
logger.log(
|
||||
'error',
|
||||
`NOTCACHED: not caching response for ${matchRequest.url} due to status ${newResponse.status} and type ${newResponse.type}`
|
||||
@@ -155,6 +155,10 @@ export class CacheManager {
|
||||
if (!headers.has('Access-Control-Allow-Origin')) {
|
||||
headers.set('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
headers.set('Vary', 'Origin');
|
||||
if (!headers.has('Access-Control-Expose-Headers')) {
|
||||
headers.set('Access-Control-Expose-Headers', '*')
|
||||
}
|
||||
if (!headers.has('Access-Control-Allow-Methods')) {
|
||||
headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user