Add cache-control directive to frequently requested content

Remove redundant header from upstream response

Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
Joe Ma 2022-10-13 01:31:43 +08:00
parent 3c900bc92a
commit 5cb9fef9a7
No known key found for this signature in database
GPG key ID: 7A0ECF5F5EDC587F

View file

@ -116,7 +116,11 @@ export default {
} }
if (path === '/api' && method == 'GET') { if (path === '/api' && method == 'GET') {
return new Response(API_SPEC_TEXT); return new Response(API_SPEC_TEXT, {
headers: {
'cache-control': 'public, max-age=172800',
},
});
} }
if (path === '/') { if (path === '/') {
@ -128,12 +132,13 @@ export default {
cacheEverything: true, cacheEverything: true,
}, },
}).then(value => { }).then(value => {
let res = new Response(value.body, value); return new Response(value.body, {
// Add the correct content-type to response header // Add the correct content-type to response header
res.headers.set('content-type', 'text/html; charset=UTF-8;'); headers: {
// Remove the default CSP header 'content-type': 'text/html; charset=UTF-8;',
res.headers.delete('content-security-policy'); 'cache-control': 'public, max-age=172800',
return res; },
});
}); });
} }
@ -389,7 +394,7 @@ export default {
method: 'GET', method: 'GET',
}); });
res = new Response(origin.body, origin); res = new Response(origin.body);
if (res.status == 404) { if (res.status == 404) {
// UUID exists in index but not found in remote object storage service, probably expired // UUID exists in index but not found in remote object storage service, probably expired
@ -407,13 +412,6 @@ export default {
}); });
} }
// Remove x-amz-* headers
for (let [key, value] of res.headers.entries()) {
if (key.startsWith('x-amz')) {
res.headers.delete(key);
}
}
res.headers.set('cache-control', 'public, max-age=18000'); res.headers.set('cache-control', 'public, max-age=18000');
res.headers.set('content-disposition', res.headers.set('content-disposition',
`inline; filename="${encodeURIComponent(descriptor.title ?? uuid)}"`); `inline; filename="${encodeURIComponent(descriptor.title ?? uuid)}"`);