From de686ec446b786a7f30089da0b900ce634922737 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sat, 27 Mar 2021 17:44:54 +0000 Subject: [PATCH] Kommentare ergaenzt --- src/de/uhilger/minsrv/handler/FileHandler.java | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/src/de/uhilger/minsrv/handler/FileHandler.java b/src/de/uhilger/minsrv/handler/FileHandler.java index 190f7a5..570e4e2 100644 --- a/src/de/uhilger/minsrv/handler/FileHandler.java +++ b/src/de/uhilger/minsrv/handler/FileHandler.java @@ -57,6 +57,7 @@ public static final String ACCEPT_RANGES_HEADER = "Accept-Ranges"; public static final String LAST_MODIFIED_DATE_HEADER = "Last-Modified"; public static final String CONTENT_TYPE = "Content-Type"; + public static final String CONTENT_LENGTH = "Content-Length"; /* Statuscodes */ public static final int SC_OK = 200; @@ -110,7 +111,7 @@ if (headers.containsKey(RANGE_HEADER)) { serveFileParts(e, new File(fileBase, fName)); } else { - if (fName.endsWith(Server.STR_SLASH)) { + if (fName.length() < 1 || fName.endsWith(Server.STR_SLASH)) { fName += WELCOME_FILE; } serveFile(e, new File(fileBase, fName)); @@ -143,6 +144,7 @@ protected void serveFile(HttpExchange e, File file) throws IOException { if (file.exists()) { setHeaders(e, file); + e.getResponseHeaders().set(CONTENT_LENGTH, Long.toString(file.length())); e.sendResponseHeaders(SC_OK, file.length()); if(HTTP_GET.equalsIgnoreCase(e.getRequestMethod())) { InputStream in = new FileInputStream(file); -- Gitblit v1.9.3