diff --git a/src/serve_font.js b/src/serve_font.js index 4403553..d8ac041 100644 --- a/src/serve_font.js +++ b/src/serve_font.js @@ -42,6 +42,7 @@ export async function serve_font(options, allowedFonts, programOpts) { if (sanitizedFontStack.length == 0) { return res.status(400).send('Invalid font stack format'); } + fontstack = decodeURI(sanitizedFontStack); let range = req.params.range; 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 { const concatenated = await getFontsPbf( options.serveAllFonts ? null : allowedFonts, diff --git a/src/serve_rendered.js b/src/serve_rendered.js index e3047ee..ef5cf30 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -665,7 +665,9 @@ async function handleTileRequest( const modifiedSince = req.get('if-modified-since'); const cc = req.get('cache-control'); 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); } } diff --git a/src/serve_style.js b/src/serve_style.js index bfc1a45..b6ff0e2 100644 --- a/src/serve_style.js +++ b/src/serve_style.js @@ -143,7 +143,9 @@ export const serve_style = { const modifiedSince = req.get('if-modified-since'); const cc = req.get('cache-control'); 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); } } @@ -327,6 +329,7 @@ export const serve_style = { spritePaths, publicUrl, name: styleJSON.name, + lastModified: new Date().toUTCString(), }; return true;