From 908789a8152867ed7414ea2a6c34afee4182f548 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Sun, 25 Feb 2024 02:15:34 +0100 Subject: [PATCH] Add more cache-control headers to integrated webserver --- .../bluemap/common/web/FileRequestHandler.java | 9 +-------- .../bluemap/common/web/MapStorageRequestHandler.java | 6 ++++++ BlueMapCommon/webapp/public/assets/emptyTile.json | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) delete mode 100644 BlueMapCommon/webapp/public/assets/emptyTile.json diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java index 4d0a9589..af960e77 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java @@ -43,11 +43,9 @@ public class FileRequestHandler implements HttpRequestHandler { private final Path webRoot; - private final File emptyTileFile; public FileRequestHandler(Path webRoot) { this.webRoot = webRoot.normalize(); - this.emptyTileFile = webRoot.resolve("assets").resolve("emptyTile.json").toFile(); } @Override @@ -90,11 +88,6 @@ private HttpResponse generateResponse(HttpRequest request) { file = new File(filePath + "/index.html"); } - // send empty tile-file if tile not exists - if (!file.exists() && file.toPath().startsWith(webRoot.resolve("maps"))){ - file = emptyTileFile; - } - if (!file.exists() || file.isDirectory()) { return new HttpResponse(HttpStatusCode.NOT_FOUND); } @@ -135,7 +128,7 @@ private HttpResponse generateResponse(HttpRequest request) { response.addHeader("ETag", eTag); if (lastModified > 0) response.addHeader("Last-Modified", timestampToString(lastModified)); response.addHeader("Cache-Control", "public"); - response.addHeader("Cache-Control", "max-age=" + TimeUnit.HOURS.toSeconds(1)); + response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1)); //add content type header String filetype = file.getName(); diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java index b66a9871..96bdadd9 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java @@ -39,6 +39,7 @@ import java.io.*; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -109,6 +110,9 @@ public HttpResponse handle(HttpRequest request) { if (lastModified > 0) response.addHeader("Last-Modified", timestampToString(lastModified)); + response.addHeader("Cache-Control", "public"); + response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1)); + if (lod == 0) response.addHeader("Content-Type", "application/octet-stream"); else response.addHeader("Content-Type", "image/png"); @@ -122,6 +126,8 @@ public HttpResponse handle(HttpRequest request) { if (optIn.isPresent()) { CompressedInputStream compressedIn = new CompressedInputStream(optIn.get(), Compression.NONE); HttpResponse response = new HttpResponse(HttpStatusCode.OK); + response.addHeader("Cache-Control", "public"); + response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1)); response.addHeader("Content-Type", ContentTypeRegistry.fromFileName(path)); writeToResponse(compressedIn, response, request); return response; diff --git a/BlueMapCommon/webapp/public/assets/emptyTile.json b/BlueMapCommon/webapp/public/assets/emptyTile.json deleted file mode 100644 index 9e26dfee..00000000 --- a/BlueMapCommon/webapp/public/assets/emptyTile.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file