Basisklassen zum Modul jdk.httpserver
ulrich
2021-07-03 f9b15dc42ba641cefef8360e4bea6035d9f7e26e
Helfer fuer Attribute hinzugefuegt
1 files modified
28 ■■■■ changed files
src/de/uhilger/httpserver/base/HttpHelper.java 28 ●●●● patch | view | raw | blame | history
src/de/uhilger/httpserver/base/HttpHelper.java
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
/**
 * Helfer fuer HTTP-Methoden
@@ -70,17 +71,28 @@
    return sb.toString();
  }
  
  public String getAttrStr(Map attributes, String key, String defaultValue) {
    Object value = attributes.get(key);
    if(value instanceof String) {
      return value.toString();
    } else {
      return defaultValue;
    }
  }
  public File tryWelcomeFiles(HttpExchange e, String fName) {
    String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString();
    String welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES).toString();
    String[] fileNames = welcomeFiles.split(FileHandler.STR_COMMA);
    boolean notFound = true;
    int i = -1;
    File file = null;
    while(notFound && ++i < fileNames.length) {
      file = new File(fileBase, fName + fileNames[i]);
      if(file.exists()) {
        notFound = false;
    String fileBase = e.getHttpContext().getAttributes().get(FileHandler.ATTR_FILE_BASE).toString();
    Object welcomeFiles = e.getHttpContext().getAttributes().get(FileHandler.ATTR_WELCOME_FILES);
    if(welcomeFiles instanceof String) {
      String[] fileNames = welcomeFiles.toString().split(FileHandler.STR_COMMA);
      int i = -1;
      while(notFound && ++i < fileNames.length) {
        file = new File(fileBase, fName + fileNames[i]);
        if(file.exists()) {
          notFound = false;
        }
      }
    }
    if(notFound) {