use consistent cache control
This commit is contained in:
parent
7e67f40fbf
commit
23f50d01a6
3 changed files with 18 additions and 2 deletions
|
@ -42,6 +42,7 @@ export async function serve_font(options, allowedFonts, programOpts) {
|
||||||
if (sanitizedFontStack.length == 0) {
|
if (sanitizedFontStack.length == 0) {
|
||||||
return res.status(400).send('Invalid font stack format');
|
return res.status(400).send('Invalid font stack format');
|
||||||
}
|
}
|
||||||
|
|
||||||
fontstack = decodeURI(sanitizedFontStack);
|
fontstack = decodeURI(sanitizedFontStack);
|
||||||
let range = req.params.range;
|
let range = req.params.range;
|
||||||
const rangeMatch = range?.match(/^[\d-]+$/);
|
const rangeMatch = range?.match(/^[\d-]+$/);
|
||||||
|
@ -54,6 +55,16 @@ export async function serve_font(options, allowedFonts, programOpts) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modifiedSince = req.get('if-modified-since');
|
||||||
|
const cc = req.get('cache-control');
|
||||||
|
if (modifiedSince && (!cc || cc.indexOf('no-cache') === -1)) {
|
||||||
|
const lastDate = new Date(lastModified).getTime();
|
||||||
|
const modDate = new Date(modifiedSince).getTime();
|
||||||
|
if (lastDate === modDate) {
|
||||||
|
return res.sendStatus(304);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const concatenated = await getFontsPbf(
|
const concatenated = await getFontsPbf(
|
||||||
options.serveAllFonts ? null : allowedFonts,
|
options.serveAllFonts ? null : allowedFonts,
|
||||||
|
|
|
@ -665,7 +665,9 @@ async function handleTileRequest(
|
||||||
const modifiedSince = req.get('if-modified-since');
|
const modifiedSince = req.get('if-modified-since');
|
||||||
const cc = req.get('cache-control');
|
const cc = req.get('cache-control');
|
||||||
if (modifiedSince && (!cc || cc.indexOf('no-cache') === -1)) {
|
if (modifiedSince && (!cc || cc.indexOf('no-cache') === -1)) {
|
||||||
if (new Date(item.lastModified) <= new Date(modifiedSince)) {
|
const lastDate = new Date(item.lastModified).getTime();
|
||||||
|
const modDate = new Date(modifiedSince).getTime();
|
||||||
|
if (lastDate === modDate) {
|
||||||
return res.sendStatus(304);
|
return res.sendStatus(304);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,9 @@ export const serve_style = {
|
||||||
const modifiedSince = req.get('if-modified-since');
|
const modifiedSince = req.get('if-modified-since');
|
||||||
const cc = req.get('cache-control');
|
const cc = req.get('cache-control');
|
||||||
if (modifiedSince && (!cc || cc.indexOf('no-cache') === -1)) {
|
if (modifiedSince && (!cc || cc.indexOf('no-cache') === -1)) {
|
||||||
if (new Date(item.lastModified) <= new Date(modifiedSince)) {
|
const lastDate = new Date(item.lastModified).getTime();
|
||||||
|
const modDate = new Date(modifiedSince).getTime();
|
||||||
|
if (lastDate === modDate) {
|
||||||
return res.sendStatus(304);
|
return res.sendStatus(304);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,6 +329,7 @@ export const serve_style = {
|
||||||
spritePaths,
|
spritePaths,
|
||||||
publicUrl,
|
publicUrl,
|
||||||
name: styleJSON.name,
|
name: styleJSON.name,
|
||||||
|
lastModified: new Date().toUTCString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue