mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 02:26:00 +01:00
Add more cache-control headers to integrated webserver
This commit is contained in:
parent
b02b91d3bb
commit
908789a815
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -1 +0,0 @@
|
||||
{}
|
Loading…
Reference in New Issue
Block a user