    public void doResponse(Properties conProp, httpHeader requestHeader, OutputStream out, InputStream body) {
        this.connectionProperties = conProp;
        String path = null;
        try {
            String method = conProp.getProperty(httpHeader.CONNECTION_PROP_METHOD);
            path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);
            String argsString = conProp.getProperty(httpHeader.CONNECTION_PROP_ARGS); 
            String httpVersion= conProp.getProperty(httpHeader.CONNECTION_PROP_HTTP_VER);
            if (path.indexOf("..") >= 0) {
                httpd.sendRespondError(conProp,out,4,403,null,"Access not allowed",null);
                return;
            }
            try {
                path = URLDecoder.decode(path, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                assert(false) : "UnsupportedEncodingException: " + e.getMessage();
            }
            String authorization = (String) requestHeader.get(httpHeader.AUTHORIZATION);
            String adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", "");
            int pos = path.lastIndexOf(".");
            if ((path.substring(0,(pos==-1)?path.length():pos)).endsWith("_p") && (adminAccountBase64MD5.length() != 0)) {
                if(sb.userDB.hasAdminRight(authorization, conProp.getProperty("CLIENTIP"), requestHeader.getHeaderCookies())){
                    serverCore.bfHost.remove(conProp.getProperty("CLIENTIP"));
                }else if(authorization != null && sb.staticAdminAuthenticated(authorization.trim().substring(6))==4){
                    serverCore.bfHost.remove(conProp.getProperty("CLIENTIP"));
                }else if (authorization == null) {
                    httpHeader headers = getDefaultHeaders(path);
                    headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"admin log-in\"");
                    servletProperties tp=new servletProperties();
                    tp.put("returnto", path);
                    httpd.sendRespondError(conProp, out, 5, 401, "Wrong Authentication", "", new File("proxymsg/authfail.inc"), tp, null, headers);
                    return;
                } else {
                    String clientIP = conProp.getProperty("CLIENTIP", "unknown-host");
                    serverLog.logInfo("HTTPD", "Wrong log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
                    Integer attempts = (Integer) serverCore.bfHost.get(clientIP);
                    if (attempts == null)
                        serverCore.bfHost.put(clientIP, new Integer(1));
                    else
                        serverCore.bfHost.put(clientIP, new Integer(attempts.intValue() + 1));
                    httpHeader headers = getDefaultHeaders(path);
                    headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"admin log-in\"");
                    httpd.sendRespondHeader(conProp,out,httpVersion,401,headers);
                    return;
                }
            }
            serverObjects args = new serverObjects();
            int argc;
            if (argsString == null) {
                int length = 0;
                if (method.equals(httpHeader.METHOD_POST)) {
                    GZIPInputStream gzipBody = null;
                    if (requestHeader.containsKey(httpHeader.CONTENT_LENGTH)) {
                        length = Integer.parseInt((String) requestHeader.get(httpHeader.CONTENT_LENGTH));
                    } else if (requestHeader.gzip()) {
                        length = -1;
                        gzipBody = new GZIPInputStream(body);
                    }
                    if ((requestHeader.containsKey(httpHeader.CONTENT_TYPE)) &&
                            (((String) requestHeader.get(httpHeader.CONTENT_TYPE)).toLowerCase().startsWith("multipart"))) {
                        HashMap files = httpd.parseMultipart(requestHeader, args, (gzipBody!=null)?gzipBody:body, length);
                        if (files != null) {
                            Iterator fit = files.entrySet().iterator();
                            Map.Entry entry;
                            while (fit.hasNext()) {
                                entry = (Map.Entry) fit.next();
                                args.put(((String) entry.getKey()) + "$file", entry.getValue());
                            }
                        }
                        argc = Integer.parseInt((String) requestHeader.get("ARGC"));
                    } else {
                        argc = httpd.parseArgs(args, (gzipBody!=null)?gzipBody:body, length);
                    }
                } else {
                    argsString = null;
                    args = null;
                    argc = 0;
                }
            } else {
                argc = httpd.parseArgs(args, argsString);
            }
            if (argc > 0) {
                Enumeration e = args.elements(); 
                Object val;
                while (e.hasMoreElements()) {
                    val = e.nextElement();
                    if ((val != null) && (val instanceof String) && (((String) val).indexOf("<script") >= 0)) {
                        httpd.sendRespondError(conProp,out,4,403,null,"bad post values",null);
                        return;
                    }
                }
            }
            if (path.length() == 0) {
                httpd.sendRespondError(conProp,out,4,400,null,"Bad Request",null);
                out.flush();
                return;
            }
            File targetClass=null;
            if (!(path.startsWith("/"))) path = "/" + path; 
            String localeSelection = switchboard.getConfig("htLocaleSelection","default");
            if (args != null && (args.containsKey("language"))) 
            {
                localeSelection = args.get("language", localeSelection);
                if (localeSelection.indexOf(".") != -1)
                    localeSelection = localeSelection.substring(0, localeSelection.indexOf("."));
            }
            File   targetFile  = getLocalizedFile(path, localeSelection);
            String targetExt   = conProp.getProperty("EXT","");
            targetClass = rewriteClassFile(new File(htDefaultPath, path));
            if (path.endsWith("/")) {
                String testpath;
                for (int i = 0; i < defaultFiles.length; i++) {
                    testpath = path + defaultFiles[i];
                    targetFile = getOverlayedFile(testpath);
                    targetClass=getOverlayedClass(testpath);
                    if (targetFile.exists()) {
                        path = testpath;
                        break;
                    }
                }
                if(targetFile == null || !targetFile.exists()){
                	String dirlistFormat = (args==null)?"html":args.get("format","html");
                    targetFile = getOverlayedFile("/htdocsdefault/dir." + dirlistFormat);
                    targetClass=getOverlayedClass("/htdocsdefault/dir." + dirlistFormat);
                    if(! (( targetFile != null && targetFile.exists()) && ( targetClass != null && targetClass.exists())) ){
                        httpd.sendRespondError(this.connectionProperties,out,3,500,"dir." + dirlistFormat + " or dir.class not found.",null,null);
                    }
                }
            }else{
                    if ( !(targetFile.exists()) && !((path.endsWith("png")||path.endsWith("gif")||path.endsWith(".stream"))&&targetClass!=null ) ){
                        targetFile = new File(htDocsPath, path);
                        targetClass = rewriteClassFile(new File(htDocsPath, path));
                    }
            }
            servletProperties tp = new servletProperties();
            Date targetDate;
            boolean nocache = false;
            if ((targetClass != null) && (path.endsWith("png"))) {
                Object img = null;
                try {
                    requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                    requestHeader.put("PATH", path);
                    img = invokeServlet(targetClass, requestHeader, args);
                } catch (InvocationTargetException e) {
                    this.theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
                    e.getMessage() +
                    " target exception at " + targetClass + ": " +
                    e.getTargetException().toString() + ":" +
                    e.getTargetException().getMessage() +
                    "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'",e);
                    targetClass = null;
                }
                if (img == null) {
                    httpd.sendRespondError(this.connectionProperties,out,3,404,"File not Found",null,null);
                } else {
                    if (img instanceof ymageMatrix) {
                        ymageMatrix yp = (ymageMatrix) img;
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                        String mimeType = mimeTable.getProperty(targetExt, "text/html");
                        serverByteBuffer baos = new serverByteBuffer();
                        ImageIO.write(yp.getImage(), targetExt, baos);
                        byte[] result = baos.toByteArray();
                        baos.close();
                        baos = null;
                        httpd.sendRespondHeader(this.connectionProperties, out,
                                httpVersion, 200, null, mimeType,
                                result.length, targetDate, null, null, null,
                                null, nocache);
                        if (!method.equals(httpHeader.METHOD_HEAD)) {
                            Thread.sleep(200); 
                            serverFileUtils.write(result, out);
                        }
                    }
                    if (img instanceof Image) {
                        Image i = (Image) img;
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                        String mimeType = mimeTable.getProperty(targetExt, "text/html");
                        int width = i.getWidth(null); if (width < 0) width = 96; 
                        int height = i.getHeight(null); if (height < 0) height = 96; 
                        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                        bi.createGraphics().drawImage(i, 0, 0, width, height, null); 
                        serverByteBuffer baos = new serverByteBuffer();
                        ImageIO.write(bi, targetExt, baos);
                        byte[] result = baos.toByteArray();
                        baos.close();
                        baos = null;
                        httpd.sendRespondHeader(this.connectionProperties, out,
                                httpVersion, 200, null, mimeType,
                                result.length, targetDate, null, null, null,
                                null, nocache);
                        if (!method.equals(httpHeader.METHOD_HEAD)) {
                            Thread.sleep(200); 
                            serverFileUtils.write(result, out);
                        }
                    }
                }
            } else if ((targetClass != null) && (path.endsWith(".stream"))) {
                requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                requestHeader.put("PATH", path);
                requestHeader.put("INPUTSTREAM", body);
                requestHeader.put("OUTPUTSTREAM", out);
                httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null);                
                 invokeServlet(targetClass, requestHeader, args);
                this.forceConnectionClose();
                return;                
            } else if ((targetFile.exists()) && (targetFile.canRead())) {
                String mimeType = mimeTable.getProperty(targetExt,"text/html");
                byte[] result;
                boolean zipContent = requestHeader.acceptGzip() && httpd.shallTransportZipped("." + conProp.getProperty("EXT",""));
                if (path.endsWith("html") || 
                        path.endsWith("xml") || 
                        path.endsWith("rss") || 
                        path.endsWith("csv") ||
                        path.endsWith("pac") ||
                        path.endsWith("src") ||
                        path.endsWith("/")) {
                    if (targetClass == null) {
                        targetDate = new Date(targetFile.lastModified());
                    } else {
                        try {
                            requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                            requestHeader.put("PATH", path);
                            Object tmp = invokeServlet(targetClass, requestHeader, args); 
                            if(tmp instanceof serverObjects){
                                tp=new servletProperties((serverObjects)tmp);
                            }else{
                                tp=(servletProperties)tmp;
                            }
                            if (tp == null) tp = new servletProperties();
                            if (tp.containsKey("AUTHENTICATE")) {
                                if (authorization != null) {
                                    String clientIP = conProp.getProperty("CLIENTIP", "unknown-host");
                                    serverLog.logInfo("HTTPD", "dynamic log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
                                    Integer attempts = (Integer) serverCore.bfHost.get(clientIP);
                                    if (attempts == null)
                                        serverCore.bfHost.put(clientIP, new Integer(1));
                                    else
                                        serverCore.bfHost.put(clientIP, new Integer(attempts.intValue() + 1));
                                }
                                httpHeader headers = getDefaultHeaders(path);
                                headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"" + tp.get("AUTHENTICATE", "") + "\"");
                                httpd.sendRespondHeader(conProp,out,httpVersion,401,headers);
                                return;
                            } else if (tp.containsKey("LOCATION")) {
                                String location = tp.get("LOCATION","");
                                if (location.length() == 0) location = path;
                                httpHeader headers = getDefaultHeaders(path);
                                headers.setCookieVector(tp.getOutgoingHeader().getCookieVector()); 
                                headers.put(httpHeader.LOCATION,location);
                                httpd.sendRespondHeader(conProp,out,httpVersion,302,headers);
                                return;
                            }
                            tp.put("version", switchboard.getConfig("version", ""));
                            tp.put("uptime", ((System.currentTimeMillis() - Long.parseLong(switchboard.getConfig("startupTime","0"))) / 1000) / 60); 
                            tp.put("clientname", switchboard.getConfig("peerName", "anomic"));
                        } catch (InvocationTargetException e) {
                            if (e.getCause() instanceof InterruptedException) {
                                throw new InterruptedException(e.getCause().getMessage());
                            }                            
                            this.theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
                                    e.getMessage() +
                                    " target exception at " + targetClass + ": " +
                                    e.getTargetException().toString() + ":" +
                                    e.getTargetException().getMessage(),e);
                            targetClass = null;
                            throw e;
                        }
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                    }
                    tp.putAll(templates);
                    serverByteBuffer o = null;
                    InputStream fis = null;
                    GZIPOutputStream zippedOut = null;
                    try {
                        byte[] templateContent = null;
                        if (useTemplateCache) {
                            long fileSize = targetFile.length();
                            if (fileSize <= 512*1024) {
                                SoftReference ref = (SoftReference) templateCache.get(targetFile);
                                if (ref != null) {
                                    templateContent = (byte[]) ref.get();
                                    if (templateContent == null) 
                                        templateCache.remove(targetFile);                               
                                }
                                if (templateContent == null) {
                                    templateContent = serverFileUtils.read(targetFile);
                                    ref = new SoftReference(templateContent);
                                    templateCache.put(targetFile,ref);
                                    if (this.theLogger.isLoggable(Level.FINEST))
                                        this.theLogger.logFinest("Cache MISS for file " + targetFile);
                                } else {
                                    if (this.theLogger.isLoggable(Level.FINEST))
                                        this.theLogger.logFinest("Cache HIT for file " + targetFile);
                                }
                                fis = new ByteArrayInputStream(templateContent);                            
                                templateContent = null;
                            } else {
                                fis = new BufferedInputStream(new FileInputStream(targetFile));
                            }
                        } else {
                            fis = new BufferedInputStream(new FileInputStream(targetFile));
                        }
                        String supertemplate="";
                        if(tp.containsKey("SUPERTEMPLATE")){
                            supertemplate=(String) tp.get("SUPERTEMPLATE");
                        }
                        if(!supertemplate.equals("")){
                            File pageFile=getOverlayedFile(supertemplate); 
                            File pageClass=getOverlayedClass(supertemplate);
                            if(pageFile != null && pageFile.exists()){
                                BufferedReader br=new BufferedReader(new InputStreamReader(fis));
                                String line;
                                boolean inheader=false;
                                StringBuffer header=new StringBuffer();
                                StringBuffer content=new StringBuffer();
                                String content_s,header_s;
                                while((line=br.readLine())!=null){
                                    if(!inheader){
                                        if(line.startsWith("<!--HEADER")){
                                            inheader=true;
                                        }else{
                                            content.append(line);
                                        }
                                    }else{
                                        if(line.endsWith("HEADER-->")){
                                            inheader=false;
                                        }else{
                                            header.append(line);
                                        }
                                    }
                                }
                                o = new serverByteBuffer();
                                fis=new ByteArrayInputStream(content.toString().getBytes());
                                httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes());
                                content_s=o.toString();
                                o = new serverByteBuffer();
                                fis=new ByteArrayInputStream(header.toString().getBytes());
                                httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes());
                                header_s=o.toString();
                                if (pageClass != null && pageClass.exists()){
                                    Object tmp = invokeServlet(pageClass, requestHeader, args); 
                                    if(tmp instanceof serverObjects){
                                        tp=new servletProperties((serverObjects)tmp);
                                    }else{
                                        tp=(servletProperties)tmp;
                                    }
                                }else
                                    tp = new servletProperties();
                                tp.put("header", header_s);
                                tp.put("page", content_s);
                                fis=new BufferedInputStream(new FileInputStream(pageFile));
                            }
                        }
                        o = new serverByteBuffer();
                        if (zipContent) zippedOut = new GZIPOutputStream(o);
                        httpTemplate.writeTemplate(fis, (zipContent) ? (OutputStream)zippedOut: (OutputStream)o, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));
                        if (zipContent) {
                            zippedOut.finish();
                            zippedOut.flush();
                            zippedOut.close();
                            zippedOut = null;
                        }
                        result = o.toByteArray();
                        if (this.md5Digest != null) {
                            this.md5Digest.reset();
                            this.md5Digest.update(result);
                            byte[] digest = this.md5Digest.digest();
                            StringBuffer digestString = new StringBuffer();
                            for ( int i = 0; i < digest.length; i++ )
                                digestString.append(Integer.toHexString( digest[i]&0xff));
                        }                        
                    } finally {
                        if (zippedOut != null) try {zippedOut.close();} catch(Exception e) {}
                        if (o != null) try {o.close(); o = null;} catch(Exception e) {}
                        if (fis != null) try {fis.close(); fis=null;} catch(Exception e) {}
                    }
                    long contentLength     = result.length;
                    String contentEncoding = (zipContent)?"gzip":null;
                    httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, contentLength, targetDate, null, tp.getOutgoingHeader(), contentEncoding, null, nocache);
                    if (! method.equals(httpHeader.METHOD_HEAD)) {
                        Thread.sleep(200); 
                        serverFileUtils.write(result, out);
                    }                    
                } else { 
                    int statusCode = 200;
                    int rangeStartOffset = 0;
                    httpHeader header = new httpHeader();
                    header.put(httpHeader.ACCEPT_RANGES, "bytes");
                    String targetMD5 = null;
                    File targetMd5File = new File(targetFile + ".md5");
                    try {
                        if (targetMd5File.exists()) {
                            targetMD5 = new String(serverFileUtils.read(targetMd5File));
                            pos = targetMD5.indexOf('\n');
                           if (pos >= 0) {
                               targetMD5 = targetMD5.substring(0, pos);
                           }         
                           header.put(httpHeader.ETAG, targetMD5);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }                        
                    if (requestHeader.containsKey(httpHeader.RANGE)) {
                        Object ifRange = requestHeader.ifRange();
                        if ((ifRange == null)||
                            (ifRange instanceof Date && targetFile.lastModified() == ((Date)ifRange).getTime()) ||
                            (ifRange instanceof String && ifRange.equals(targetMD5))) {
                            String rangeHeaderVal = ((String) requestHeader.get(httpHeader.RANGE)).trim();
                            if (rangeHeaderVal.startsWith("bytes=")) {
                                String rangesVal = rangeHeaderVal.substring("bytes=".length());
                                String[] ranges = rangesVal.split(",");
                                if ((ranges.length == 1)&&(ranges[0].endsWith("-"))) {
                                    rangeStartOffset = Integer.valueOf(ranges[0].substring(0,ranges[0].length()-1)).intValue();
                                    statusCode = 206;
                                    if (header == null) header = new httpHeader();
                                    header.put(httpHeader.CONTENT_RANGE, "bytes " + rangeStartOffset + "-" + (targetFile.length()-1) + "/" + targetFile.length());
                                }
                            }
                        }
                    }
                    targetDate = new Date(targetFile.lastModified());
                    long   contentLength    = (zipContent)?-1:targetFile.length()-rangeStartOffset;
                    String contentEncoding  = (zipContent)?"gzip":null;
                    String transferEncoding = (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1))?null:(zipContent)?"chunked":null;
                    if (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && zipContent) forceConnectionClose();
                    httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, statusCode, null, mimeType, contentLength, targetDate, null, header, contentEncoding, transferEncoding, nocache);
                    if (!method.equals(httpHeader.METHOD_HEAD)) {                        
                        httpChunkedOutputStream chunkedOut = null;
                        GZIPOutputStream zipped = null;
                        OutputStream newOut = out;
                        if (transferEncoding != null) {
                            chunkedOut = new httpChunkedOutputStream(newOut);
                            newOut = chunkedOut;
                        }
                        if (contentEncoding != null) {
                            zipped = new GZIPOutputStream(newOut);
                            newOut = zipped;
                        }
                        serverFileUtils.copyRange(targetFile,newOut,rangeStartOffset);
                        if (zipped != null) {
                            zipped.flush();
                            zipped.finish();
                        }
                        if (chunkedOut != null) {
                            chunkedOut.finish();
                        }
                    }   
                }
            } else {
                httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);
                return;
            }
        } catch (Exception e) {     
            try {
                int httpStatusCode = 400; 
                String httpStatusText = null; 
                StringBuffer errorMessage = new StringBuffer(); 
                Exception errorExc = null;            
                String errorMsg = e.getMessage();
                if (
                        (e instanceof InterruptedException) ||
                        ((errorMsg != null) && (errorMsg.startsWith("Socket closed")) && (Thread.currentThread().isInterrupted()))
                   ) {
                    errorMessage.append("Interruption detected while processing query.");
                    httpStatusCode = 503;
                } else {
                    if ((errorMsg != null) && 
                        (
                           errorMsg.startsWith("Broken pipe") || 
                           errorMsg.startsWith("Connection reset") ||
                           errorMsg.startsWith("Software caused connection abort")                           
                       )) {
                        errorMessage.append("Client unexpectedly closed connection while processing query.");
                    } else if ((errorMsg != null) && (errorMsg.startsWith("Connection timed out"))) {
                        errorMessage.append("Connection timed out.");
                    } else {
                        errorMessage.append("Unexpected error while processing query.");
                        httpStatusCode = 500;
                        errorExc = e;
                    }
                }
                errorMessage.append("\nSession: ").append(Thread.currentThread().getName())
                            .append("\nQuery:   ").append(path)
                            .append("\nClient:  ").append(conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP,"unknown")) 
                            .append("\nReason:  ").append(e.toString());    
                if (!conProp.containsKey(httpHeader.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
                    httpd.sendRespondError(conProp,out, 4, httpStatusCode, httpStatusText, errorMessage.toString(),errorExc);
                } else {
                    this.forceConnectionClose();
                }    
                if (httpStatusCode == 500) {
                    this.theLogger.logWarning(errorMessage.toString(),e);
                }
            } catch (Exception ee) {
                this.forceConnectionClose();
            }            
        } finally {
            try {out.flush();}catch (Exception e) {}
            if (((String)requestHeader.get(httpHeader.CONNECTION, "close")).indexOf("keep-alive") == -1) {
                try {Thread.sleep(1000);} catch (InterruptedException e) {}
            }
        }
    }

    public void doResponse(Properties conProp, httpHeader requestHeader, OutputStream out, InputStream body) {
        this.connectionProperties = conProp;
        String path = null;
        try {
            String method = conProp.getProperty(httpHeader.CONNECTION_PROP_METHOD);
            path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);
            String argsString = conProp.getProperty(httpHeader.CONNECTION_PROP_ARGS); 
            String httpVersion= conProp.getProperty(httpHeader.CONNECTION_PROP_HTTP_VER);
            if (path.indexOf("..") >= 0) {
                httpd.sendRespondError(conProp,out,4,403,null,"Access not allowed",null);
                return;
            }
            try {
                path = URLDecoder.decode(path, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                assert(false) : "UnsupportedEncodingException: " + e.getMessage();
            }
            String authorization = (String) requestHeader.get(httpHeader.AUTHORIZATION);
            String adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", "");
            int pos = path.lastIndexOf(".");
            if ((path.substring(0,(pos==-1)?path.length():pos)).endsWith("_p") && (adminAccountBase64MD5.length() != 0)) {
                if(sb.userDB.hasAdminRight(authorization, conProp.getProperty("CLIENTIP"), requestHeader.getHeaderCookies())){
                    serverCore.bfHost.remove(conProp.getProperty("CLIENTIP"));
                }else if(authorization != null && sb.staticAdminAuthenticated(authorization.trim().substring(6))==4){
                    serverCore.bfHost.remove(conProp.getProperty("CLIENTIP"));
                }else if (authorization == null) {
                    httpHeader headers = getDefaultHeaders(path);
                    headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"admin log-in\"");
                    servletProperties tp=new servletProperties();
                    tp.put("returnto", path);
                    httpd.sendRespondError(conProp, out, 5, 401, "Wrong Authentication", "", new File("proxymsg/authfail.inc"), tp, null, headers);
                    return;
                } else {
                    String clientIP = conProp.getProperty("CLIENTIP", "unknown-host");
                    serverLog.logInfo("HTTPD", "Wrong log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
                    Integer attempts = (Integer) serverCore.bfHost.get(clientIP);
                    if (attempts == null)
                        serverCore.bfHost.put(clientIP, new Integer(1));
                    else
                        serverCore.bfHost.put(clientIP, new Integer(attempts.intValue() + 1));
                    httpHeader headers = getDefaultHeaders(path);
                    headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"admin log-in\"");
                    httpd.sendRespondHeader(conProp,out,httpVersion,401,headers);
                    return;
                }
            }
            serverObjects args = new serverObjects();
            int argc;
            if (argsString == null) {
                int length = 0;
                if (method.equals(httpHeader.METHOD_POST)) {
                    GZIPInputStream gzipBody = null;
                    if (requestHeader.containsKey(httpHeader.CONTENT_LENGTH)) {
                        length = Integer.parseInt((String) requestHeader.get(httpHeader.CONTENT_LENGTH));
                    } else if (requestHeader.gzip()) {
                        length = -1;
                        gzipBody = new GZIPInputStream(body);
                    }
                    if ((requestHeader.containsKey(httpHeader.CONTENT_TYPE)) &&
                            (((String) requestHeader.get(httpHeader.CONTENT_TYPE)).toLowerCase().startsWith("multipart"))) {
                        HashMap files = httpd.parseMultipart(requestHeader, args, (gzipBody!=null)?gzipBody:body, length);
                        if (files != null) {
                            Iterator fit = files.entrySet().iterator();
                            Map.Entry entry;
                            while (fit.hasNext()) {
                                entry = (Map.Entry) fit.next();
                                args.put(((String) entry.getKey()) + "$file", entry.getValue());
                            }
                        }
                        argc = Integer.parseInt((String) requestHeader.get("ARGC"));
                    } else {
                        argc = httpd.parseArgs(args, (gzipBody!=null)?gzipBody:body, length);
                    }
                } else {
                    argsString = null;
                    args = null;
                    argc = 0;
                }
            } else {
                argc = httpd.parseArgs(args, argsString);
            }
            if (argc > 0) {
                Enumeration e = args.elements(); 
                Object val;
                while (e.hasMoreElements()) {
                    val = e.nextElement();
                    if ((val != null) && (val instanceof String) && (((String) val).indexOf("<script") >= 0)) {
                        httpd.sendRespondError(conProp,out,4,403,null,"bad post values",null);
                        return;
                    }
                }
            }
            if (path.length() == 0) {
                httpd.sendRespondError(conProp,out,4,400,null,"Bad Request",null);
                out.flush();
                return;
            }
            File targetClass=null;
            if (!(path.startsWith("/"))) path = "/" + path; 
            String localeSelection = switchboard.getConfig("htLocaleSelection","default");
            if (args != null && (args.containsKey("language"))) 
            {
                localeSelection = args.get("language", localeSelection);
                if (localeSelection.indexOf(".") != -1)
                    localeSelection = localeSelection.substring(0, localeSelection.indexOf("."));
            }
            File   targetFile  = getLocalizedFile(path, localeSelection);
            String targetExt   = conProp.getProperty("EXT","");
            targetClass = rewriteClassFile(new File(htDefaultPath, path));
            if (path.endsWith("/")) {
                String testpath;
                for (int i = 0; i < defaultFiles.length; i++) {
                    testpath = path + defaultFiles[i];
                    targetFile = getOverlayedFile(testpath);
                    targetClass=getOverlayedClass(testpath);
                    if (targetFile.exists()) {
                        path = testpath;
                        break;
                    }
                }
                if(targetFile == null || !targetFile.exists()){
                	String dirlistFormat = (args==null)?"html":args.get("format","html");
                    targetFile = getOverlayedFile("/htdocsdefault/dir." + dirlistFormat);
                    targetClass=getOverlayedClass("/htdocsdefault/dir." + dirlistFormat);
                    if(! (( targetFile != null && targetFile.exists()) && ( targetClass != null && targetClass.exists())) ){
                        httpd.sendRespondError(this.connectionProperties,out,3,500,"dir." + dirlistFormat + " or dir.class not found.",null,null);
                    }
                }
            }else{
                    if ( !(targetFile.exists()) && !((path.endsWith("png")||path.endsWith("gif")||path.endsWith(".stream"))&&targetClass!=null ) ){
                        targetFile = new File(htDocsPath, path);
                        targetClass = rewriteClassFile(new File(htDocsPath, path));
                    }
            }
            servletProperties tp = new servletProperties();
            Date targetDate;
            boolean nocache = false;
            if ((targetClass != null) && (path.endsWith("png"))) {
                Object img = null;
                try {
                    requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                    requestHeader.put("PATH", path);
                    img = invokeServlet(targetClass, requestHeader, args);
                } catch (InvocationTargetException e) {
                    this.theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
                    e.getMessage() +
                    " target exception at " + targetClass + ": " +
                    e.getTargetException().toString() + ":" +
                    e.getTargetException().getMessage() +
                    "; java.awt.graphicsenv='" + System.getProperty("java.awt.graphicsenv","") + "'",e);
                    targetClass = null;
                }
                if (img == null) {
                    httpd.sendRespondError(this.connectionProperties,out,3,404,"File not Found",null,null);
                } else {
                    if (img instanceof ymageMatrix) {
                        ymageMatrix yp = (ymageMatrix) img;
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                        String mimeType = mimeTable.getProperty(targetExt, "text/html");
                        serverByteBuffer baos = new serverByteBuffer();
                        ImageIO.write(yp.getImage(), targetExt, baos);
                        byte[] result = baos.toByteArray();
                        baos.close();
                        baos = null;
                        httpd.sendRespondHeader(this.connectionProperties, out,
                                httpVersion, 200, null, mimeType,
                                result.length, targetDate, null, null, null,
                                null, nocache);
                        if (!method.equals(httpHeader.METHOD_HEAD)) {
                            Thread.sleep(200); 
                            serverFileUtils.write(result, out);
                        }
                    }
                    if (img instanceof Image) {
                        Image i = (Image) img;
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                        String mimeType = mimeTable.getProperty(targetExt, "text/html");
                        int width = i.getWidth(null); if (width < 0) width = 96; 
                        int height = i.getHeight(null); if (height < 0) height = 96; 
                        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                        bi.createGraphics().drawImage(i, 0, 0, width, height, null); 
                        serverByteBuffer baos = new serverByteBuffer();
                        ImageIO.write(bi, targetExt, baos);
                        byte[] result = baos.toByteArray();
                        baos.close();
                        baos = null;
                        httpd.sendRespondHeader(this.connectionProperties, out,
                                httpVersion, 200, null, mimeType,
                                result.length, targetDate, null, null, null,
                                null, nocache);
                        if (!method.equals(httpHeader.METHOD_HEAD)) {
                            Thread.sleep(200); 
                            serverFileUtils.write(result, out);
                        }
                    }
                }
            } else if ((targetClass != null) && (path.endsWith(".stream"))) {
                requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                requestHeader.put("PATH", path);
                requestHeader.put("INPUTSTREAM", body);
                requestHeader.put("OUTPUTSTREAM", out);
                httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null);                
                 invokeServlet(targetClass, requestHeader, args);
                this.forceConnectionClose();
                return;                
            } else if ((targetFile.exists()) && (targetFile.canRead())) {
                String mimeType = mimeTable.getProperty(targetExt,"text/html");
                byte[] result;
                boolean zipContent = requestHeader.acceptGzip() && httpd.shallTransportZipped("." + conProp.getProperty("EXT",""));
                if (path.endsWith("html") || 
                        path.endsWith("xml") || 
                        path.endsWith("rss") || 
                        path.endsWith("csv") ||
                        path.endsWith("pac") ||
                        path.endsWith("src") ||
                        path.endsWith("/")) {
                    if (targetClass == null) {
                        targetDate = new Date(targetFile.lastModified());
                    } else {
                        try {
                            requestHeader.put("CLIENTIP", conProp.getProperty("CLIENTIP"));
                            requestHeader.put("PATH", path);
                            Object tmp = invokeServlet(targetClass, requestHeader, args); 
                            if(tmp instanceof serverObjects){
                                tp=new servletProperties((serverObjects)tmp);
                            }else{
                                tp=(servletProperties)tmp;
                            }
                            if (tp == null) tp = new servletProperties();
                            if (tp.containsKey("AUTHENTICATE")) {
                                if (authorization != null) {
                                    String clientIP = conProp.getProperty("CLIENTIP", "unknown-host");
                                    serverLog.logInfo("HTTPD", "dynamic log-in for account 'admin' in http file handler for path '" + path + "' from host '" + clientIP + "'");
                                    Integer attempts = (Integer) serverCore.bfHost.get(clientIP);
                                    if (attempts == null)
                                        serverCore.bfHost.put(clientIP, new Integer(1));
                                    else
                                        serverCore.bfHost.put(clientIP, new Integer(attempts.intValue() + 1));
                                }
                                httpHeader headers = getDefaultHeaders(path);
                                headers.put(httpHeader.WWW_AUTHENTICATE,"Basic realm=\"" + tp.get("AUTHENTICATE", "") + "\"");
                                httpd.sendRespondHeader(conProp,out,httpVersion,401,headers);
                                return;
                            } else if (tp.containsKey("LOCATION")) {
                                String location = tp.get("LOCATION","");
                                if (location.length() == 0) location = path;
                                httpHeader headers = getDefaultHeaders(path);
                                headers.setCookieVector(tp.getOutgoingHeader().getCookieVector()); 
                                headers.put(httpHeader.LOCATION,location);
                                httpd.sendRespondHeader(conProp,out,httpVersion,302,headers);
                                return;
                            }
                            tp.put("version", switchboard.getConfig("version", ""));
                            tp.put("uptime", ((System.currentTimeMillis() - Long.parseLong(switchboard.getConfig("startupTime","0"))) / 1000) / 60); 
                            tp.put("clientname", switchboard.getConfig("peerName", "anomic"));
                        } catch (InvocationTargetException e) {
                            if (e.getCause() instanceof InterruptedException) {
                                throw new InterruptedException(e.getCause().getMessage());
                            }                            
                            this.theLogger.logSevere("INTERNAL ERROR: " + e.toString() + ":" +
                                    e.getMessage() +
                                    " target exception at " + targetClass + ": " +
                                    e.getTargetException().toString() + ":" +
                                    e.getTargetException().getMessage(),e);
                            targetClass = null;
                            throw e;
                        }
                        targetDate = new Date(System.currentTimeMillis());
                        nocache = true;
                    }
                    tp.putAll(templates);
                    serverByteBuffer o = null;
                    InputStream fis = null;
                    GZIPOutputStream zippedOut = null;
                    try {
                        byte[] templateContent = null;
                        if (useTemplateCache) {
                            long fileSize = targetFile.length();
                            if (fileSize <= 512*1024) {
                                SoftReference ref = (SoftReference) templateCache.get(targetFile);
                                if (ref != null) {
                                    templateContent = (byte[]) ref.get();
                                    if (templateContent == null) 
                                        templateCache.remove(targetFile);                               
                                }
                                if (templateContent == null) {
                                    templateContent = serverFileUtils.read(targetFile);
                                    ref = new SoftReference(templateContent);
                                    templateCache.put(targetFile,ref);
                                    if (this.theLogger.isLoggable(Level.FINEST))
                                        this.theLogger.logFinest("Cache MISS for file " + targetFile);
                                } else {
                                    if (this.theLogger.isLoggable(Level.FINEST))
                                        this.theLogger.logFinest("Cache HIT for file " + targetFile);
                                }
                                fis = new ByteArrayInputStream(templateContent);                            
                                templateContent = null;
                            } else {
                                fis = new BufferedInputStream(new FileInputStream(targetFile));
                            }
                        } else {
                            fis = new BufferedInputStream(new FileInputStream(targetFile));
                        }
                        String supertemplate="";
                        if(tp.containsKey("SUPERTEMPLATE")){
                            supertemplate=(String) tp.get("SUPERTEMPLATE");
                        }
                        if(!supertemplate.equals("")){
                            File pageFile=getOverlayedFile(supertemplate); 
                            File pageClass=getOverlayedClass(supertemplate);
                            if(pageFile != null && pageFile.exists()){
                                BufferedReader br=new BufferedReader(new InputStreamReader(fis));
                                String line;
                                boolean inheader=false;
                                StringBuffer header=new StringBuffer();
                                StringBuffer content=new StringBuffer();
                                String content_s,header_s;
                                while((line=br.readLine())!=null){
                                    if(!inheader){
                                        if(line.startsWith("<!--HEADER")){
                                            inheader=true;
                                        }else{
                                            content.append(line);
                                        }
                                    }else{
                                        if(line.endsWith("HEADER-->")){
                                            inheader=false;
                                        }else{
                                            header.append(line);
                                        }
                                    }
                                }
                                o = new serverByteBuffer();
                                fis=new ByteArrayInputStream(content.toString().getBytes());
                                httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes());
                                content_s=o.toString();
                                o = new serverByteBuffer();
                                fis=new ByteArrayInputStream(header.toString().getBytes());
                                httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes());
                                header_s=o.toString();
                                if (pageClass != null && pageClass.exists()){
                                    Object tmp = invokeServlet(pageClass, requestHeader, args); 
                                    if(tmp instanceof serverObjects){
                                        tp=new servletProperties((serverObjects)tmp);
                                    }else{
                                        tp=(servletProperties)tmp;
                                    }
                                }else
                                    tp = new servletProperties();
                                tp.putASIS("header", header_s);
                                tp.putASIS("page", content_s);
                                fis=new BufferedInputStream(new FileInputStream(pageFile));
                            }
                        }
                        o = new serverByteBuffer();
                        if (zipContent) zippedOut = new GZIPOutputStream(o);
                        httpTemplate.writeTemplate(fis, (zipContent) ? (OutputStream)zippedOut: (OutputStream)o, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));
                        if (zipContent) {
                            zippedOut.finish();
                            zippedOut.flush();
                            zippedOut.close();
                            zippedOut = null;
                        }
                        result = o.toByteArray();
                        if (this.md5Digest != null) {
                            this.md5Digest.reset();
                            this.md5Digest.update(result);
                            byte[] digest = this.md5Digest.digest();
                            StringBuffer digestString = new StringBuffer();
                            for ( int i = 0; i < digest.length; i++ )
                                digestString.append(Integer.toHexString( digest[i]&0xff));
                        }                        
                    } finally {
                        if (zippedOut != null) try {zippedOut.close();} catch(Exception e) {}
                        if (o != null) try {o.close(); o = null;} catch(Exception e) {}
                        if (fis != null) try {fis.close(); fis=null;} catch(Exception e) {}
                    }
                    long contentLength     = result.length;
                    String contentEncoding = (zipContent)?"gzip":null;
                    httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, contentLength, targetDate, null, tp.getOutgoingHeader(), contentEncoding, null, nocache);
                    if (! method.equals(httpHeader.METHOD_HEAD)) {
                        Thread.sleep(200); 
                        serverFileUtils.write(result, out);
                    }                    
                } else { 
                    int statusCode = 200;
                    int rangeStartOffset = 0;
                    httpHeader header = new httpHeader();
                    header.put(httpHeader.ACCEPT_RANGES, "bytes");
                    String targetMD5 = null;
                    File targetMd5File = new File(targetFile + ".md5");
                    try {
                        if (targetMd5File.exists()) {
                            targetMD5 = new String(serverFileUtils.read(targetMd5File));
                            pos = targetMD5.indexOf('\n');
                           if (pos >= 0) {
                               targetMD5 = targetMD5.substring(0, pos);
                           }         
                           header.put(httpHeader.ETAG, targetMD5);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }                        
                    if (requestHeader.containsKey(httpHeader.RANGE)) {
                        Object ifRange = requestHeader.ifRange();
                        if ((ifRange == null)||
                            (ifRange instanceof Date && targetFile.lastModified() == ((Date)ifRange).getTime()) ||
                            (ifRange instanceof String && ifRange.equals(targetMD5))) {
                            String rangeHeaderVal = ((String) requestHeader.get(httpHeader.RANGE)).trim();
                            if (rangeHeaderVal.startsWith("bytes=")) {
                                String rangesVal = rangeHeaderVal.substring("bytes=".length());
                                String[] ranges = rangesVal.split(",");
                                if ((ranges.length == 1)&&(ranges[0].endsWith("-"))) {
                                    rangeStartOffset = Integer.valueOf(ranges[0].substring(0,ranges[0].length()-1)).intValue();
                                    statusCode = 206;
                                    if (header == null) header = new httpHeader();
                                    header.put(httpHeader.CONTENT_RANGE, "bytes " + rangeStartOffset + "-" + (targetFile.length()-1) + "/" + targetFile.length());
                                }
                            }
                        }
                    }
                    targetDate = new Date(targetFile.lastModified());
                    long   contentLength    = (zipContent)?-1:targetFile.length()-rangeStartOffset;
                    String contentEncoding  = (zipContent)?"gzip":null;
                    String transferEncoding = (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1))?null:(zipContent)?"chunked":null;
                    if (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && zipContent) forceConnectionClose();
                    httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, statusCode, null, mimeType, contentLength, targetDate, null, header, contentEncoding, transferEncoding, nocache);
                    if (!method.equals(httpHeader.METHOD_HEAD)) {                        
                        httpChunkedOutputStream chunkedOut = null;
                        GZIPOutputStream zipped = null;
                        OutputStream newOut = out;
                        if (transferEncoding != null) {
                            chunkedOut = new httpChunkedOutputStream(newOut);
                            newOut = chunkedOut;
                        }
                        if (contentEncoding != null) {
                            zipped = new GZIPOutputStream(newOut);
                            newOut = zipped;
                        }
                        serverFileUtils.copyRange(targetFile,newOut,rangeStartOffset);
                        if (zipped != null) {
                            zipped.flush();
                            zipped.finish();
                        }
                        if (chunkedOut != null) {
                            chunkedOut.finish();
                        }
                    }   
                }
            } else {
                httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);
                return;
            }
        } catch (Exception e) {     
            try {
                int httpStatusCode = 400; 
                String httpStatusText = null; 
                StringBuffer errorMessage = new StringBuffer(); 
                Exception errorExc = null;            
                String errorMsg = e.getMessage();
                if (
                        (e instanceof InterruptedException) ||
                        ((errorMsg != null) && (errorMsg.startsWith("Socket closed")) && (Thread.currentThread().isInterrupted()))
                   ) {
                    errorMessage.append("Interruption detected while processing query.");
                    httpStatusCode = 503;
                } else {
                    if ((errorMsg != null) && 
                        (
                           errorMsg.startsWith("Broken pipe") || 
                           errorMsg.startsWith("Connection reset") ||
                           errorMsg.startsWith("Software caused connection abort")                           
                       )) {
                        errorMessage.append("Client unexpectedly closed connection while processing query.");
                    } else if ((errorMsg != null) && (errorMsg.startsWith("Connection timed out"))) {
                        errorMessage.append("Connection timed out.");
                    } else {
                        errorMessage.append("Unexpected error while processing query.");
                        httpStatusCode = 500;
                        errorExc = e;
                    }
                }
                errorMessage.append("\nSession: ").append(Thread.currentThread().getName())
                            .append("\nQuery:   ").append(path)
                            .append("\nClient:  ").append(conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP,"unknown")) 
                            .append("\nReason:  ").append(e.toString());    
                if (!conProp.containsKey(httpHeader.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
                    httpd.sendRespondError(conProp,out, 4, httpStatusCode, httpStatusText, errorMessage.toString(),errorExc);
                } else {
                    this.forceConnectionClose();
                }    
                if (httpStatusCode == 500) {
                    this.theLogger.logWarning(errorMessage.toString(),e);
                }
            } catch (Exception ee) {
                this.forceConnectionClose();
            }            
        } finally {
            try {out.flush();}catch (Exception e) {}
            if (((String)requestHeader.get(httpHeader.CONNECTION, "close")).indexOf("keep-alive") == -1) {
                try {Thread.sleep(1000);} catch (InterruptedException e) {}
            }
        }
    }
