From 1f6776f237cb98c1222ee9dd2f75220de0d02c34 Mon Sep 17 00:00:00 2001 From: ulrich Date: Sun, 01 Dec 2024 17:07:47 +0000 Subject: [PATCH] wireActors zugunsten von Scanner aufgeloest --- src/de/uhilger/neon/FileServer.java | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/de/uhilger/neon/FileServer.java b/src/de/uhilger/neon/FileServer.java index cfb8ce6..86aef24 100644 --- a/src/de/uhilger/neon/FileServer.java +++ b/src/de/uhilger/neon/FileServer.java @@ -53,22 +53,24 @@ public static final String STR_COMMA = ","; public static final String STR_DOT = "."; public static final String STR_EMPTY = ""; + public static final String STR_EQUAL = "="; 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 { - File fileToDeliver = new File((String) exchange + String fName = exchange.getRequestURI().getPath(); + try { + fName = new HttpHelper().getFileName(exchange); + String fBase = (String) exchange .getHttpContext().getAttributes() - .getOrDefault(ATTR_FILE_BASE, STR_EMPTY), fName); + .getOrDefault(ATTR_FILE_BASE, STR_EMPTY); + //File fileToDeliver = new File((String) exchange + // .getHttpContext().getAttributes() + // .getOrDefault(ATTR_FILE_BASE, STR_EMPTY), fName); + File fileToDeliver = new File(fBase, fName); Headers headers = exchange.getRequestHeaders(); if (headers.containsKey(RANGE_HEADER)) { 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 +78,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