From 19c3c55e8120312c41fd008da799a7e47f53a5bb Mon Sep 17 00:00:00 2001
From: ulrich
Date: Sat, 26 Oct 2024 12:08:49 +0000
Subject: [PATCH] fixFileName hinzugefuegt

---
 src/de/uhilger/neon/FileServer.java |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/de/uhilger/neon/FileServer.java b/src/de/uhilger/neon/FileServer.java
index cfb8ce6..b768961 100644
--- a/src/de/uhilger/neon/FileServer.java
+++ b/src/de/uhilger/neon/FileServer.java
@@ -55,11 +55,9 @@
   public static final String STR_EMPTY = "";
   
   public void serveFile(HttpExchange exchange) throws IOException {
-    String fName = new HttpHelper().getFileName(exchange);
-    if (fName.startsWith(".")) {
-      HttpResponder fs = new HttpResponder();
-      fs.sendNotFound(exchange, fName);
-    } else {
+    String fName = exchange.getRequestURI().getPath();
+    try {
+      fName = new HttpHelper().getFileName(exchange);
       File fileToDeliver = new File((String) exchange
               .getHttpContext().getAttributes()
               .getOrDefault(ATTR_FILE_BASE, STR_EMPTY), fName);
@@ -68,7 +66,6 @@
         new PartialFileServer().serveFileParts(exchange, fileToDeliver);
       } else {
         if (fName.length() < 1 || fName.endsWith(STR_SLASH)) {
-          //HttpHelper helper = new HttpHelper();
           File welcomeFile = tryWelcomeFiles(exchange, fName);
           if(welcomeFile != null) {
             fileToDeliver = welcomeFile;
@@ -76,9 +73,11 @@
         }
         new HttpResponder().serveFile(exchange, fileToDeliver);
       }
-    }    
+    } catch(IllegalArgumentException ex) {
+      new HttpResponder().sendNotFound(exchange, fName);
+    }
   }
-
+  
   public File tryWelcomeFiles(HttpExchange e, String fName) {
     boolean notFound = true;
     File file = null;

--
Gitblit v1.9.3