Skip to content

Commit 4b8245d

Browse files
committed
Fix webserver stalling
1 parent b5e8bf4 commit 4b8245d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/FileRequestHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.nio.file.InvalidPathException;
3737
import java.nio.file.Path;
3838
import java.time.Instant;
39+
import java.time.ZoneOffset;
3940
import java.time.format.DateTimeFormatter;
4041
import java.time.format.DateTimeParseException;
4142
import java.util.concurrent.TimeUnit;
@@ -134,7 +135,10 @@ private HttpResponse generateResponse(HttpRequest request) throws IOException {
134135
//create response
135136
HttpResponse response = new HttpResponse(HttpStatusCode.OK);
136137
response.addHeader("ETag", eTag);
137-
if (lastModified > 0) response.addHeader("Last-Modified", DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(lastModified)));
138+
if (lastModified > 0) response.addHeader("Last-Modified", DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant
139+
.ofEpochMilli(lastModified)
140+
.atOffset(ZoneOffset.UTC)
141+
));
138142
response.addHeader("Cache-Control", "public");
139143
response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1));
140144

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/http/HttpConnection.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ public void accept(SelectionKey selectionKey) {
8787
() -> requestHandler.handle(request),
8888
responseHandlerExecutor
8989
);
90-
futureResponse.thenAccept(response -> {
90+
futureResponse.handle((response, error) -> {
91+
if (error != null) {
92+
Logger.global.logError("Unexpected error handling request", error);
93+
response = new HttpResponse(HttpStatusCode.INTERNAL_SERVER_ERROR);
94+
}
95+
9196
try {
9297
response.read(channel); // do an initial read to trigger response sending intent
9398
this.response = response;
9499
} catch (IOException e) {
95100
handleIOException(channel, e);
96101
}
102+
103+
return null;
97104
});
98105
}
99106

0 commit comments

Comments
 (0)