mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-09-30 08:07:38 +02:00
Fix webserver stalling
This commit is contained in:
parent
b5e8bf42ae
commit
4b8245d19d
@ -36,6 +36,7 @@
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -134,7 +135,10 @@ private HttpResponse generateResponse(HttpRequest request) throws IOException {
|
||||
//create response
|
||||
HttpResponse response = new HttpResponse(HttpStatusCode.OK);
|
||||
response.addHeader("ETag", eTag);
|
||||
if (lastModified > 0) response.addHeader("Last-Modified", DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(lastModified)));
|
||||
if (lastModified > 0) response.addHeader("Last-Modified", DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant
|
||||
.ofEpochMilli(lastModified)
|
||||
.atOffset(ZoneOffset.UTC)
|
||||
));
|
||||
response.addHeader("Cache-Control", "public");
|
||||
response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1));
|
||||
|
||||
|
@ -87,13 +87,20 @@ public void accept(SelectionKey selectionKey) {
|
||||
() -> requestHandler.handle(request),
|
||||
responseHandlerExecutor
|
||||
);
|
||||
futureResponse.thenAccept(response -> {
|
||||
futureResponse.handle((response, error) -> {
|
||||
if (error != null) {
|
||||
Logger.global.logError("Unexpected error handling request", error);
|
||||
response = new HttpResponse(HttpStatusCode.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
try {
|
||||
response.read(channel); // do an initial read to trigger response sending intent
|
||||
this.response = response;
|
||||
} catch (IOException e) {
|
||||
handleIOException(channel, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user