| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | } |
| | | new HttpResponder().serveFile(exchange, fileToDeliver); |
| | | } |
| | | } catch(IllegalArgumentException ex) { |
| | | new HttpResponder().sendNotFound(exchange, fName); |
| | | } |
| | | } |
| | | |