Replaced a widely-used Property Object in the httpd with HashMap<String, Object> which is not synchronized like Properties

A synchronization is not needed here and applies an overhead to the httpd process which is now removed.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7745 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent cc239b18cd
commit 746e3c3b06

@ -142,7 +142,7 @@ public class FTPLoader {
response = getFile(ftpClient, request, acceptOnlyParseable); response = getFile(ftpClient, request, acceptOnlyParseable);
} catch (final Exception e) { } catch (final Exception e) {
// add message to errorLog // add message to errorLog
e.printStackTrace(); Log.logException(e);
(new PrintStream(berr)).print(e.getMessage()); (new PrintStream(berr)).print(e.getMessage());
} }
} }

@ -195,13 +195,13 @@ public class SMBLoader {
} }
} }
} catch (SmbException e) { } catch (SmbException e) {
e.printStackTrace(); Log.logException(e);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); Log.logException(e);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); Log.logException(e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.logException(e);
} }
} }
} }

@ -6,6 +6,7 @@ import java.io.FileInputStream;
import java.util.Properties; import java.util.Properties;
import net.yacy.cora.document.MultiProtocolURI; import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.kelondro.logging.Log;
public class MimeTable { public class MimeTable {
@ -19,7 +20,7 @@ public class MimeTable {
mimeTableInputStream = new BufferedInputStream(new FileInputStream(mimeFile)); mimeTableInputStream = new BufferedInputStream(new FileInputStream(mimeFile));
mimeTable.load(mimeTableInputStream); mimeTable.load(mimeTableInputStream);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); Log.logException(e);
} finally { } finally {
if (mimeTableInputStream != null) try { mimeTableInputStream.close(); } catch (final Exception e1) {} if (mimeTableInputStream != null) try { mimeTableInputStream.close(); } catch (final Exception e1) {}
} }

@ -76,10 +76,10 @@ import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -234,28 +234,28 @@ public final class HTTPDFileHandler {
return headers; return headers;
} }
public static void doGet(final Properties conProp, final RequestHeader requestHeader, final OutputStream response) { public static void doGet(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream response) {
doResponse(conProp, requestHeader, response, null); doResponse(conProp, requestHeader, response, null);
} }
public static void doHead(final Properties conProp, final RequestHeader requestHeader, final OutputStream response) { public static void doHead(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream response) {
doResponse(conProp, requestHeader, response, null); doResponse(conProp, requestHeader, response, null);
} }
public static void doPost(final Properties conProp, final RequestHeader requestHeader, final OutputStream response, final InputStream body) { public static void doPost(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream response, final InputStream body) {
doResponse(conProp, requestHeader, response, body); doResponse(conProp, requestHeader, response, body);
} }
public static void doResponse(final Properties conProp, final RequestHeader requestHeader, final OutputStream out, final InputStream body) { public static void doResponse(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream out, final InputStream body) {
String path = null; String path = null;
try { try {
// getting some connection properties // getting some connection properties
final String method = conProp.getProperty(HeaderFramework.CONNECTION_PROP_METHOD); final String method = (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD);
path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH);
String argsString = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); // is null if no args were given String argsString = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // is null if no args were given
final String httpVersion = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVersion = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
final String clientIP = conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP, "unknown-host"); String clientIP = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); if (clientIP == null) clientIP = "unknown-host";
// check hack attacks in path // check hack attacks in path
if (path.indexOf("..") >= 0) { if (path.indexOf("..") >= 0) {
@ -348,7 +348,7 @@ public final class HTTPDFileHandler {
} }
// Authentication successful. remove brute-force flag // Authentication successful. remove brute-force flag
serverCore.bfHost.remove(conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP)); serverCore.bfHost.remove(conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
// parse arguments // parse arguments
serverObjects args = new serverObjects(); serverObjects args = new serverObjects();
@ -438,7 +438,7 @@ public final class HTTPDFileHandler {
} }
File targetFile = getLocalizedFile(path, localeSelection); File targetFile = getLocalizedFile(path, localeSelection);
final String targetExt = conProp.getProperty("EXT",""); String targetExt = (String) conProp.get("EXT"); if (targetExt == null) targetExt = "";
targetClass = rewriteClassFile(new File(htDefaultPath, path)); targetClass = rewriteClassFile(new File(htDefaultPath, path));
if (path.endsWith("/") || path.endsWith("\\")) { if (path.endsWith("/") || path.endsWith("\\")) {
String testpath; String testpath;
@ -558,7 +558,7 @@ public final class HTTPDFileHandler {
// call an image-servlet to produce an on-the-fly - generated image // call an image-servlet to produce an on-the-fly - generated image
Object img = null; Object img = null;
try { try {
requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP)); requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path); requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "png"); requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "png");
// in case that there are no args given, args = null or empty hashmap // in case that there are no args given, args = null or empty hashmap
@ -747,7 +747,7 @@ public final class HTTPDFileHandler {
indexOfDelimiter = cgiHeader[i].indexOf(':'); indexOfDelimiter = cgiHeader[i].indexOf(':');
key = cgiHeader[i].substring(0, indexOfDelimiter).trim(); key = cgiHeader[i].substring(0, indexOfDelimiter).trim();
value = cgiHeader[i].substring(indexOfDelimiter + 1).trim(); value = cgiHeader[i].substring(indexOfDelimiter + 1).trim();
conProp.setProperty(key, value); conProp.put(key, value);
if (key.equals("Cache-Control") && value.equals("no-cache")) { if (key.equals("Cache-Control") && value.equals("no-cache")) {
nocache = true; nocache = true;
} else if (key.equals("Content-type")) { } else if (key.equals("Content-type")) {
@ -786,7 +786,7 @@ public final class HTTPDFileHandler {
} else if ((targetClass != null) && (path.endsWith(".stream"))) { } else if ((targetClass != null) && (path.endsWith(".stream"))) {
// call rewrite-class // call rewrite-class
requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP)); requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path); requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "stream"); requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, "stream");
//requestHeader.put(httpHeader.CONNECTION_PROP_INPUTSTREAM, body); //requestHeader.put(httpHeader.CONNECTION_PROP_INPUTSTREAM, body);
@ -803,7 +803,8 @@ public final class HTTPDFileHandler {
// if this file uses templates, then we use the template // if this file uses templates, then we use the template
// re-write - method to create an result // re-write - method to create an result
String mimeType = MimeTable.ext2mime(targetExt, "text/html"); String mimeType = MimeTable.ext2mime(targetExt, "text/html");
final boolean zipContent = requestHeader.acceptGzip() && HTTPDemon.shallTransportZipped("." + conProp.getProperty("EXT","")); String ext = (String) conProp.get("EXT"); if (ext == null) ext = "";
final boolean zipContent = requestHeader.acceptGzip() && HTTPDemon.shallTransportZipped("." + ext);
if (path.endsWith("html") || if (path.endsWith("html") ||
path.endsWith("htm") || path.endsWith("htm") ||
path.endsWith("xml") || path.endsWith("xml") ||
@ -833,7 +834,7 @@ public final class HTTPDFileHandler {
if (targetClass != null) { if (targetClass != null) {
// CGI-class: call the class to create a property for rewriting // CGI-class: call the class to create a property for rewriting
try { try {
requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP)); requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path); requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, path);
int ep = path.lastIndexOf("."); int ep = path.lastIndexOf(".");
requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, path.substring(ep + 1)); requestHeader.put(HeaderFramework.CONNECTION_PROP_EXT, path.substring(ep + 1));
@ -1141,7 +1142,7 @@ public final class HTTPDFileHandler {
errorMessage.append("\nSession: ").append(Thread.currentThread().getName()) errorMessage.append("\nSession: ").append(Thread.currentThread().getName())
.append("\nQuery: ").append(path) .append("\nQuery: ").append(path)
.append("\nClient: ").append(conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP,"unknown")) .append("\nClient: ").append(conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP))
.append("\nReason: ").append(e.getMessage()); .append("\nReason: ").append(e.getMessage());
if (!conProp.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_HEADER)) { if (!conProp.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
@ -1192,9 +1193,9 @@ public final class HTTPDFileHandler {
return targetFile; return targetFile;
} }
private static final void forceConnectionClose(final Properties conprop) { private static final void forceConnectionClose(final HashMap<String, Object> conprop) {
if (conprop != null) { if (conprop != null) {
conprop.setProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close"); conprop.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close");
} }
} }
@ -1292,8 +1293,8 @@ public final class HTTPDFileHandler {
* not in separete servlet, because we need access to binary outstream * not in separete servlet, because we need access to binary outstream
* @throws IOException * @throws IOException
*/ */
private static void doURLProxy(final serverObjects args, final Properties conProp, final RequestHeader requestHeader, OutputStream out) throws IOException { private static void doURLProxy(final serverObjects args, final HashMap<String, Object> conProp, final RequestHeader requestHeader, OutputStream out) throws IOException {
final String httpVersion = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVersion = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
URL proxyurl = null; URL proxyurl = null;
if (args != null && args.containsKey("url")) { if (args != null && args.containsKey("url")) {
@ -1301,12 +1302,12 @@ public final class HTTPDFileHandler {
proxyurl = new URL(strUrl); proxyurl = new URL(strUrl);
} }
// set properties for proxy connection // set properties for proxy connection
final Properties prop = new Properties(); final HashMap<String, Object> prop = new HashMap<String, Object>();
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1); prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, proxyurl.getHost()); prop.put(HeaderFramework.CONNECTION_PROP_HOST, proxyurl.getHost());
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getPath().replaceAll(" ", "%20")); prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getPath().replaceAll(" ", "%20"));
prop.setProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE, "PROXY"); prop.put(HeaderFramework.CONNECTION_PROP_REQUESTLINE, "PROXY");
prop.setProperty("CLIENTIP", "0:0:0:0:0:0:0:1"); prop.put("CLIENTIP", "0:0:0:0:0:0:0:1");
// remove some stuff from request header, so it isn't send to the server // remove some stuff from request header, so it isn't send to the server
requestHeader.remove("CLIENTIP"); requestHeader.remove("CLIENTIP");
@ -1336,7 +1337,7 @@ public final class HTTPDFileHandler {
return; return;
} }
final int httpStatus = Integer.parseInt(prop.getProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS)); final int httpStatus = Integer.parseInt((String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS));
if (outgoingHeader.getContentType().startsWith("text/html")) { if (outgoingHeader.getContentType().startsWith("text/html")) {
StringWriter buffer = new StringWriter(); StringWriter buffer = new StringWriter();
@ -1378,7 +1379,7 @@ public final class HTTPDFileHandler {
out.write(sbb); out.write(sbb);
} else { } else {
if (!outgoingHeader.containsKey(HeaderFramework.CONTENT_LENGTH)) if (!outgoingHeader.containsKey(HeaderFramework.CONTENT_LENGTH))
outgoingHeader.put(HeaderFramework.CONTENT_LENGTH, prop.getProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE)); outgoingHeader.put(HeaderFramework.CONTENT_LENGTH, (String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE));
HTTPDemon.sendRespondHeader(conProp, out, httpVersion, httpStatus, outgoingHeader); HTTPDemon.sendRespondHeader(conProp, out, httpVersion, httpStatus, outgoingHeader);
FileUtils.copy(in, out); FileUtils.copy(in, out);
} }

@ -62,9 +62,9 @@ import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager; import java.util.logging.LogManager;
@ -289,7 +289,7 @@ public final class HTTPDProxyHandler {
* @param respond the OutputStream to the client * @param respond the OutputStream to the client
* @see de.anomic.http.httpdHandler#doGet(java.util.Properties, net.yacy.cora.protocol.HeaderFramework, java.io.OutputStream) * @see de.anomic.http.httpdHandler#doGet(java.util.Properties, net.yacy.cora.protocol.HeaderFramework, java.io.OutputStream)
*/ */
public static void doGet(final Properties conProp, final RequestHeader requestHeader, final OutputStream respond) { public static void doGet(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream respond) {
ByteCountOutputStream countedRespond = null; ByteCountOutputStream countedRespond = null;
try { try {
final int reqID = requestHeader.hashCode(); final int reqID = requestHeader.hashCode();
@ -300,12 +300,12 @@ public final class HTTPDProxyHandler {
sb.proxyLastAccess = System.currentTimeMillis(); sb.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes (needed for the logfile) // using an ByteCount OutputStream to count the send bytes (needed for the logfile)
countedRespond = new ByteCountOutputStream(respond,conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY"); countedRespond = new ByteCountOutputStream(respond,((String) conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE)).length() + 2,"PROXY");
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/' String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
final String ip = conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer final String ip = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
int pos=0; int pos=0;
int port=0; int port=0;
@ -328,8 +328,8 @@ public final class HTTPDProxyHandler {
} catch(final MalformedURLException e){}//just keep the old one } catch(final MalformedURLException e){}//just keep the old one
} }
if (log.isFinest()) log.logFinest(reqID +" using redirector to "+ url); if (log.isFinest()) log.logFinest(reqID +" using redirector to "+ url);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_HOST, url.getHost()+":"+url.getPort()); conProp.put(HeaderFramework.CONNECTION_PROP_HOST, url.getHost()+":"+url.getPort());
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PATH, url.getPath()); conProp.put(HeaderFramework.CONNECTION_PROP_PATH, url.getPath());
requestHeader.put(HeaderFramework.HOST, url.getHost()+":"+url.getPort()); requestHeader.put(HeaderFramework.HOST, url.getHost()+":"+url.getPort());
requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, url.getPath()); requestHeader.put(HeaderFramework.CONNECTION_PROP_PATH, url.getPath());
} }
@ -440,20 +440,20 @@ public final class HTTPDProxyHandler {
if (countedRespond != null) countedRespond.finish(); if (countedRespond != null) countedRespond.finish();
conProp.put(HeaderFramework.CONNECTION_PROP_REQUEST_END, Long.valueOf(System.currentTimeMillis())); conProp.put(HeaderFramework.CONNECTION_PROP_REQUEST_END, Long.valueOf(System.currentTimeMillis()));
conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE,(countedRespond != null) ? Long.valueOf(countedRespond.getCount()) : -1L); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE,(countedRespond != null) ? Long.toString(countedRespond.getCount()) : -1L);
logProxyAccess(conProp); logProxyAccess(conProp);
} }
} }
private static void fulfillRequestFromWeb(final Properties conProp, final DigestURI url, final RequestHeader requestHeader, final ResponseHeader cachedResponseHeader, final OutputStream respond) { private static void fulfillRequestFromWeb(final HashMap<String, Object> conProp, final DigestURI url, final RequestHeader requestHeader, final ResponseHeader cachedResponseHeader, final OutputStream respond) {
try { try {
final int reqID = requestHeader.hashCode(); final int reqID = requestHeader.hashCode();
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/' final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
final String ip = conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer final String ip = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
final String httpVer = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); // the ip from the connecting peer final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); // the ip from the connecting peer
int port, pos; int port, pos;
if ((pos = host.indexOf(':')) < 0) { if ((pos = host.indexOf(':')) < 0) {
@ -506,7 +506,7 @@ public final class HTTPDProxyHandler {
if (b != null) sizeBeforeDelete = b.length; if (b != null) sizeBeforeDelete = b.length;
} }
Cache.delete(url); Cache.delete(url);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REFRESH_MISS"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REFRESH_MISS");
} }
// reserver cache entry // reserver cache entry
@ -594,12 +594,12 @@ public final class HTTPDProxyHandler {
} catch (IOException e) { } catch (IOException e) {
log.logWarning("cannot write " + response.url() + " to Cache (1): " + e.getMessage(), e); log.logWarning("cannot write " + response.url() + " to Cache (1): " + e.getMessage(), e);
} }
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_MISS"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_MISS");
} else if (cacheArray != null && sizeBeforeDelete == cacheArray.length) { } else if (cacheArray != null && sizeBeforeDelete == cacheArray.length) {
// before we came here we deleted a cache entry // before we came here we deleted a cache entry
cacheArray = null; cacheArray = null;
//cacheManager.push(cacheEntry); // unnecessary update //cacheManager.push(cacheEntry); // unnecessary update
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REF_FAIL_HIT"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REF_FAIL_HIT");
} else { } else {
// before we came here we deleted a cache entry // before we came here we deleted a cache entry
response.setContent(cacheArray); response.setContent(cacheArray);
@ -609,7 +609,7 @@ public final class HTTPDProxyHandler {
} catch (IOException e) { } catch (IOException e) {
log.logWarning("cannot write " + response.url() + " to Cache (2): " + e.getMessage(), e); log.logWarning("cannot write " + response.url() + " to Cache (2): " + e.getMessage(), e);
} }
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REFRESH_MISS"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE, "TCP_REFRESH_MISS");
} }
} else { } else {
// no caching // no caching
@ -621,7 +621,7 @@ public final class HTTPDProxyHandler {
// FileUtils.copy(res.getDataAsStream(), outStream); // FileUtils.copy(res.getDataAsStream(), outStream);
client.writeTo(outStream); client.writeTo(outStream);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_MISS"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_MISS");
} }
if (chunkedOut != null) { if (chunkedOut != null) {
@ -668,7 +668,7 @@ public final class HTTPDProxyHandler {
} }
private static void fulfillRequestFromCache( private static void fulfillRequestFromCache(
final Properties conProp, final HashMap<String, Object> conProp,
final DigestURI url, final DigestURI url,
final RequestHeader requestHeader, final RequestHeader requestHeader,
final ResponseHeader cachedResponseHeader, final ResponseHeader cachedResponseHeader,
@ -676,7 +676,7 @@ public final class HTTPDProxyHandler {
final OutputStream respond final OutputStream respond
) throws IOException { ) throws IOException {
final String httpVer = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
// we respond on the request by using the cache, the cache is fresh // we respond on the request by using the cache, the cache is fresh
try { try {
@ -690,7 +690,7 @@ public final class HTTPDProxyHandler {
// conditional request: freshness of cache for that condition was already // conditional request: freshness of cache for that condition was already
// checked within shallUseCache(). Now send only a 304 response // checked within shallUseCache(). Now send only a 304 response
log.logInfo("CACHE HIT/304 " + url.toString()); log.logInfo("CACHE HIT/304 " + url.toString());
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_REFRESH_HIT"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_REFRESH_HIT");
// setting the content length header to 0 // setting the content length header to 0
cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Integer.toString(0)); cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Integer.toString(0));
@ -701,7 +701,7 @@ public final class HTTPDProxyHandler {
} else { } else {
// unconditional request: send content of cache // unconditional request: send content of cache
log.logInfo("CACHE HIT/203 " + url.toString()); log.logInfo("CACHE HIT/203 " + url.toString());
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_HIT"); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"TCP_HIT");
// setting the content header to the proper length // setting the content header to the proper length
cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Long.toString(cacheEntry.length)); cachedResponseHeader.put(HeaderFramework.CONTENT_LENGTH, Long.toString(cacheEntry.length));
@ -720,7 +720,7 @@ public final class HTTPDProxyHandler {
// we do nothing here // we do nothing here
if (conProp.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_HEADER)) { if (conProp.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_HEADER)) {
log.logWarning("Error while trying to send cached message body."); log.logWarning("Error while trying to send cached message body.");
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close"); conProp.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close");
} else { } else {
HTTPDemon.sendRespondError(conProp,respond,4,503,"socket error: " + e.getMessage(),"socket error: " + e.getMessage(), e); HTTPDemon.sendRespondError(conProp,respond,4,503,"socket error: " + e.getMessage(),"socket error: " + e.getMessage(), e);
} }
@ -730,7 +730,7 @@ public final class HTTPDProxyHandler {
return; return;
} }
public static void doHead(final Properties conProp, final RequestHeader requestHeader, OutputStream respond) { public static void doHead(final HashMap<String, Object> conProp, final RequestHeader requestHeader, OutputStream respond) {
// ResponseContainer res = null; // ResponseContainer res = null;
DigestURI url = null; DigestURI url = null;
@ -743,12 +743,12 @@ public final class HTTPDProxyHandler {
sb.proxyLastAccess = System.currentTimeMillis(); sb.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes // using an ByteCount OutputStream to count the send bytes
respond = new ByteCountOutputStream(respond,conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY"); respond = new ByteCountOutputStream(respond,((String) conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE)).length() + 2,"PROXY");
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH);
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS);
final String httpVer = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
int port, pos; int port, pos;
if ((pos = host.indexOf(':')) < 0) { if ((pos = host.indexOf(':')) < 0) {
@ -845,7 +845,7 @@ public final class HTTPDProxyHandler {
} }
} }
public static void doPost(final Properties conProp, final RequestHeader requestHeader, final OutputStream respond, InputStream body) throws IOException { public static void doPost(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final OutputStream respond, InputStream body) throws IOException {
assert conProp != null : "precondition violated: conProp != null"; assert conProp != null : "precondition violated: conProp != null";
assert requestHeader != null : "precondition violated: requestHeader != null"; assert requestHeader != null : "precondition violated: requestHeader != null";
assert body != null : "precondition violated: body != null"; assert body != null : "precondition violated: body != null";
@ -860,12 +860,12 @@ public final class HTTPDProxyHandler {
sb.proxyLastAccess = System.currentTimeMillis(); sb.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes // using an ByteCount OutputStream to count the send bytes
countedRespond = new ByteCountOutputStream(respond,conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY"); countedRespond = new ByteCountOutputStream(respond,((String) conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE)).length() + 2,"PROXY");
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH);
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
final String httpVer = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
int port, pos; int port, pos;
if ((pos = host.indexOf(':')) < 0) { if ((pos = host.indexOf(':')) < 0) {
@ -970,7 +970,7 @@ public final class HTTPDProxyHandler {
} }
conProp.put(HeaderFramework.CONNECTION_PROP_REQUEST_END, Long.valueOf(System.currentTimeMillis())); conProp.put(HeaderFramework.CONNECTION_PROP_REQUEST_END, Long.valueOf(System.currentTimeMillis()));
conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE,(countedRespond != null) ? Long.valueOf(countedRespond.getCount()) : -1L); conProp.put(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE,(countedRespond != null) ? Long.toString(countedRespond.getCount()) : "-1");
logProxyAccess(conProp); logProxyAccess(conProp);
} }
} }
@ -1001,7 +1001,7 @@ public final class HTTPDProxyHandler {
* @param requestHeader * @param requestHeader
* @param hostlow * @param hostlow
*/ */
private static void prepareRequestHeader(final Properties conProp, final RequestHeader requestHeader, final String hostlow) { private static void prepareRequestHeader(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final String hostlow) {
// set another userAgent, if not yellow-listed // set another userAgent, if not yellow-listed
if ((yellowList != null) && (!(yellowList.contains(domain(hostlow))))) { if ((yellowList != null) && (!(yellowList.contains(domain(hostlow))))) {
// change the User-Agent // change the User-Agent
@ -1070,9 +1070,9 @@ public final class HTTPDProxyHandler {
* @return * @return
*/ */
private static ChunkedOutputStream setTransferEncoding( private static ChunkedOutputStream setTransferEncoding(
final Properties conProp, final ResponseHeader responseHeader, final HashMap<String, Object> conProp, final ResponseHeader responseHeader,
final int statusCode, final OutputStream respond) { final int statusCode, final OutputStream respond) {
final String httpVer = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
ChunkedOutputStream chunkedOut = null; ChunkedOutputStream chunkedOut = null;
// gzipped response is ungzipped an therefor the length is unknown // gzipped response is ungzipped an therefor the length is unknown
if (responseHeader.gzip() || responseHeader.getContentLength() < 0) { if (responseHeader.gzip() || responseHeader.getContentLength() < 0) {
@ -1119,10 +1119,10 @@ public final class HTTPDProxyHandler {
* @param conProp * @param conProp
* @param requestHeader * @param requestHeader
*/ */
private static void addXForwardedForHeader(final Properties conProp, final RequestHeader requestHeader) { private static void addXForwardedForHeader(final HashMap<String, Object> conProp, final RequestHeader requestHeader) {
// setting the X-Forwarded-For Header // setting the X-Forwarded-For Header
if (sb.getConfigBool("proxy.sendXForwardedForHeader", true)) { if (sb.getConfigBool("proxy.sendXForwardedForHeader", true)) {
requestHeader.put(HeaderFramework.X_FORWARDED_FOR, conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP)); requestHeader.put(HeaderFramework.X_FORWARDED_FOR, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));
} }
} }
@ -1183,14 +1183,14 @@ public final class HTTPDProxyHandler {
} }
} }
public static void doConnect(final Properties conProp, final RequestHeader requestHeader, final InputStream clientIn, final OutputStream clientOut) throws IOException { public static void doConnect(final HashMap<String, Object> conProp, final RequestHeader requestHeader, final InputStream clientIn, final OutputStream clientOut) throws IOException {
sb.proxyLastAccess = System.currentTimeMillis(); sb.proxyLastAccess = System.currentTimeMillis();
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String httpVersion = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER); final String httpVersion = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER);
String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH);
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS);
if (args != null) { path = path + "?" + args; } if (args != null) { path = path + "?" + args; }
int port, pos; int port, pos;
@ -1325,7 +1325,7 @@ public final class HTTPDProxyHandler {
} }
} }
private static void handleProxyException(final Exception e, final Properties conProp, final OutputStream respond, final DigestURI url) { private static void handleProxyException(final Exception e, final HashMap<String, Object> conProp, final OutputStream respond, final DigestURI url) {
// this may happen if // this may happen if
// - the targeted host does not exist // - the targeted host does not exist
// - anything with the remote server was wrong. // - anything with the remote server was wrong.
@ -1407,12 +1407,12 @@ public final class HTTPDProxyHandler {
} else { } else {
if (unknownError) { if (unknownError) {
log.logSevere("Unknown Error while processing request '" + log.logSevere("Unknown Error while processing request '" +
conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE,"unknown") + "':" + conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE) + "':" +
"\n" + Thread.currentThread().getName() + "\n" + Thread.currentThread().getName() +
"\n" + errorMessage,e); "\n" + errorMessage,e);
} else { } else {
log.logWarning("Error while processing request '" + log.logWarning("Error while processing request '" +
conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE,"unknown") + "':" + conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE) + "':" +
"\n" + Thread.currentThread().getName() + "\n" + Thread.currentThread().getName() +
"\n" + errorMessage); "\n" + errorMessage);
} }
@ -1424,13 +1424,13 @@ public final class HTTPDProxyHandler {
} }
private static void forceConnectionClose(final Properties conProp) { private static void forceConnectionClose(final HashMap<String, Object> conProp) {
if (conProp != null) { if (conProp != null) {
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close"); conProp.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close");
} }
} }
private static serverObjects unknownHostHandling(final Properties conProp) throws Exception { private static serverObjects unknownHostHandling(final HashMap<String, Object> conProp) throws Exception {
final serverObjects detailedErrorMsgMap = new serverObjects(); final serverObjects detailedErrorMsgMap = new serverObjects();
// generic toplevel domains // generic toplevel domains
@ -1464,14 +1464,16 @@ public final class HTTPDProxyHandler {
// getting some connection properties // getting some connection properties
String orgHostPort = "80"; String orgHostPort = "80";
String orgHostName = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST,"unknown").toLowerCase(); String orgHostName = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
if (orgHostName == null) orgHostName = "unknown";
orgHostName = orgHostName.toLowerCase();
int pos = orgHostName.indexOf(':'); int pos = orgHostName.indexOf(':');
if (pos != -1) { if (pos != -1) {
orgHostPort = orgHostName.substring(pos+1); orgHostPort = orgHostName.substring(pos+1);
orgHostName = orgHostName.substring(0,pos); orgHostName = orgHostName.substring(0,pos);
} }
final String orgHostPath = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH,""); String orgHostPath = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); if (orgHostPath == null) orgHostPath = "";
String orgHostArgs = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS,""); String orgHostArgs = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); if (orgHostArgs == null) orgHostArgs = "";
if (orgHostArgs.length() > 0) orgHostArgs = "?" + orgHostArgs; if (orgHostArgs.length() > 0) orgHostArgs = "?" + orgHostArgs;
detailedErrorMsgMap.put("hostName", orgHostName); detailedErrorMsgMap.put("hostName", orgHostName);
@ -1551,7 +1553,7 @@ public final class HTTPDProxyHandler {
* e.g.<br> * e.g.<br>
* <code>1117528623.857 178 192.168.1.201 TCP_MISS/200 1069 GET http://www.yacy.de/ - DIRECT/81.169.145.74 text/html</code> * <code>1117528623.857 178 192.168.1.201 TCP_MISS/200 1069 GET http://www.yacy.de/ - DIRECT/81.169.145.74 text/html</code>
*/ */
private final static synchronized void logProxyAccess(final Properties conProp) { private final static synchronized void logProxyAccess(final HashMap<String, Object> conProp) {
if (!doAccessLogging) return; if (!doAccessLogging) return;
@ -1576,31 +1578,32 @@ public final class HTTPDProxyHandler {
logMessage.append(' '); logMessage.append(' ');
// Remote Host // Remote Host
final String clientIP = conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP); final String clientIP = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP);
logMessage.append(clientIP); logMessage.append(clientIP);
logMessage.append(' '); logMessage.append(' ');
// Code/Status // Code/Status
final String respondStatus = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS); final String respondStatus = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS);
final String respondCode = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE,"UNKNOWN"); String respondCode = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_CODE);
if (respondCode == null) respondCode = "UNKNOWN";
logMessage.append(respondCode); logMessage.append(respondCode);
logMessage.append("/"); logMessage.append("/");
logMessage.append(respondStatus); logMessage.append(respondStatus);
logMessage.append(' '); logMessage.append(' ');
// Bytes // Bytes
final Long bytes = (Long) conProp.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE); final String bytes = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE);
logMessage.append(bytes.toString()); logMessage.append(bytes.toString());
logMessage.append(' '); logMessage.append(' ');
// Method // Method
final String requestMethod = conProp.getProperty(HeaderFramework.CONNECTION_PROP_METHOD); final String requestMethod = (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD);
logMessage.append(requestMethod); logMessage.append(requestMethod);
logMessage.append(' '); logMessage.append(' ');
// URL // URL
final String requestURL = conProp.getProperty(HeaderFramework.CONNECTION_PROP_URL); final String requestURL = (String) conProp.get(HeaderFramework.CONNECTION_PROP_URL);
final String requestArgs = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); final String requestArgs = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS);
logMessage.append(requestURL); logMessage.append(requestURL);
if (requestArgs != null) { if (requestArgs != null) {
logMessage.append("?") logMessage.append("?")
@ -1613,7 +1616,7 @@ public final class HTTPDProxyHandler {
logMessage.append(' '); logMessage.append(' ');
// Peerstatus/Peerhost // Peerstatus/Peerhost
final String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); final String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
logMessage.append("DIRECT/"); logMessage.append("DIRECT/");
logMessage.append(host); logMessage.append(host);
logMessage.append(' '); logMessage.append(' ');

@ -44,7 +44,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -217,7 +216,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
* @param prop * @param prop
* @return <code>true</code> if a persistent connection was requested or <code>false</code> otherwise * @return <code>true</code> if a persistent connection was requested or <code>false</code> otherwise
*/ */
private boolean handlePersistentConnection(final RequestHeader header, final Properties prop) { private boolean handlePersistentConnection(final RequestHeader header, final HashMap<String, Object> prop) {
if (!keepAliveSupport) { if (!keepAliveSupport) {
prop.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close"); prop.put(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close");
@ -225,7 +224,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
// getting the http version that is used by the client // getting the http version that is used by the client
final String httpVersion = prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, "HTTP/0.9"); String httpVersion = (String) prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = "HTTP/0.9";
// managing keep-alive: in HTTP/0.9 and HTTP/1.0 every connection is closed // managing keep-alive: in HTTP/0.9 and HTTP/1.0 every connection is closed
// afterwards. In HTTP/1.1 (and above, in the future?) connections are // afterwards. In HTTP/1.1 (and above, in the future?) connections are
@ -238,7 +237,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
final String transferEncoding = header.get(HeaderFramework.TRANSFER_ENCODING, "identity"); final String transferEncoding = header.get(HeaderFramework.TRANSFER_ENCODING, "identity");
final boolean isPostRequest = prop.getProperty(HeaderFramework.CONNECTION_PROP_METHOD).equals(HeaderFramework.METHOD_POST); final boolean isPostRequest = prop.get(HeaderFramework.CONNECTION_PROP_METHOD).equals(HeaderFramework.METHOD_POST);
final boolean hasContentLength = header.containsKey(HeaderFramework.CONTENT_LENGTH); final boolean hasContentLength = header.containsKey(HeaderFramework.CONTENT_LENGTH);
final boolean hasTransferEncoding = header.containsKey(HeaderFramework.TRANSFER_ENCODING) && !transferEncoding.equalsIgnoreCase("identity"); final boolean hasTransferEncoding = header.containsKey(HeaderFramework.TRANSFER_ENCODING) && !transferEncoding.equalsIgnoreCase("identity");
@ -251,14 +250,14 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return persistent; return persistent;
} }
private boolean handleYaCyHopAuthentication(final RequestHeader header, Properties prop, Session session) { private boolean handleYaCyHopAuthentication(final RequestHeader header, HashMap<String, Object> prop, Session session) {
// check if the user has allowed that his/her peer is used for hops // check if the user has allowed that his/her peer is used for hops
if (!allowYaCyHop(session)) return false; if (!allowYaCyHop(session)) return false;
// proxy hops must identify with 4 criteria: // proxy hops must identify with 4 criteria:
// the accessed port must not be port 80 // the accessed port must not be port 80
final String host = prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST); final String host = (String) prop.get(HeaderFramework.CONNECTION_PROP_HOST);
if (host == null) return false; if (host == null) return false;
int pos; int pos;
if ((pos = host.indexOf(':')) < 0) { if ((pos = host.indexOf(':')) < 0) {
@ -268,7 +267,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
if (Integer.parseInt(host.substring(pos + 1)) == 80) return false; if (Integer.parseInt(host.substring(pos + 1)) == 80) return false;
// the access path must be into the yacy protocol path; it must start with 'yacy' // the access path must be into the yacy protocol path; it must start with 'yacy'
if (!(prop.getProperty(HeaderFramework.CONNECTION_PROP_PATH, "").startsWith("/yacy/"))) return false; if (!(prop.containsKey(HeaderFramework.CONNECTION_PROP_PATH) && ((String) prop.get(HeaderFramework.CONNECTION_PROP_PATH)).startsWith("/yacy/"))) return false;
// the accessing client must identify with user:password, where // the accessing client must identify with user:password, where
// user = addressed peer name // user = addressed peer name
@ -285,7 +284,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// furthermore, YaCy hops must not exceed a specific access frequency // furthermore, YaCy hops must not exceed a specific access frequency
// check access requester frequency: protection against DoS against this peer // check access requester frequency: protection against DoS against this peer
final String requester = prop.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP); final String requester = (String) prop.get(HeaderFramework.CONNECTION_PROP_CLIENTIP);
if (requester == null) return false; if (requester == null) return false;
if (lastAccessDelta(YaCyHopAccessRequester, requester) < 10000) return false; if (lastAccessDelta(YaCyHopAccessRequester, requester) < 10000) return false;
YaCyHopAccessRequester.put(requester, Long.valueOf(System.currentTimeMillis())); YaCyHopAccessRequester.put(requester, Long.valueOf(System.currentTimeMillis()));
@ -303,9 +302,9 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return (lastAccess == null) ? Long.MAX_VALUE : System.currentTimeMillis() - lastAccess.longValue(); return (lastAccess == null) ? Long.MAX_VALUE : System.currentTimeMillis() - lastAccess.longValue();
} }
private boolean handleProxyAuthentication(final RequestHeader header, final Properties prop, final Session session) throws IOException { private boolean handleProxyAuthentication(final RequestHeader header, final HashMap<String, Object> prop, final Session session) throws IOException {
// getting the http version that is used by the client // getting the http version that is used by the client
final String httpVersion = prop.getProperty("HTTP", "HTTP/0.9"); String httpVersion = (String) prop.get("HTTP"); if (httpVersion == null) httpVersion = "HTTP/0.9";
// reading the authentication settings from switchboard // reading the authentication settings from switchboard
if (!this.proxyAccounts_init) { if (!this.proxyAccounts_init) {
@ -355,7 +354,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
public Boolean UNKNOWN(final String arg, final Session session) throws IOException { public Boolean UNKNOWN(final String arg, final Session session) throws IOException {
//System.out.println("UNKNOWN " + arg); //System.out.println("UNKNOWN " + arg);
Properties prop = parseRequestLine(HeaderFramework.METHOD_GET, arg, session); HashMap<String, Object> prop = parseRequestLine(HeaderFramework.METHOD_GET, arg, session);
int pos; int pos;
String unknownCommand = null, args = null; String unknownCommand = null, args = null;
if ((pos = arg.indexOf(' ')) > 0) { if ((pos = arg.indexOf(' ')) > 0) {
@ -376,10 +375,10 @@ public final class HTTPDemon implements serverHandler, Cloneable {
//System.out.println("GET " + arg); //System.out.println("GET " + arg);
try { try {
// parsing the http request line // parsing the http request line
final Properties prop = parseRequestLine(HeaderFramework.METHOD_GET, arg, session); final HashMap<String, Object> prop = parseRequestLine(HeaderFramework.METHOD_GET, arg, session);
// we now know the HTTP version. depending on that, we read the header // we now know the HTTP version. depending on that, we read the header
final String httpVersion = prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); String httpVersion = (String) prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = HeaderFramework.HTTP_VERSION_0_9;
final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9)) final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9))
? new RequestHeader(reverseMappingCache) ? new RequestHeader(reverseMappingCache)
: readHeader(prop, session); : readHeader(prop, session);
@ -390,7 +389,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// determines if the connection should be kept alive // determines if the connection should be kept alive
handlePersistentConnection(header, prop); handlePersistentConnection(header, prop);
if (prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) { if (prop.get(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) {
// pass to server // pass to server
if (allowServer(session)) { if (allowServer(session)) {
HTTPDFileHandler.doGet(prop, header, session.out); HTTPDFileHandler.doGet(prop, header, session.out);
@ -411,7 +410,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
} }
return prop.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; return prop.get(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION;
} catch (final Exception e) { } catch (final Exception e) {
logUnexpectedError(e, session.userAddress.getHostAddress()); logUnexpectedError(e, session.userAddress.getHostAddress());
return serverCore.TERMINATE_CONNECTION; return serverCore.TERMINATE_CONNECTION;
@ -443,10 +442,10 @@ public final class HTTPDemon implements serverHandler, Cloneable {
public Boolean HEAD(final String arg, final Session session) { public Boolean HEAD(final String arg, final Session session) {
//System.out.println("HEAD " + arg); //System.out.println("HEAD " + arg);
try { try {
final Properties prop = parseRequestLine(HeaderFramework.METHOD_HEAD, arg, session); final HashMap<String, Object> prop = parseRequestLine(HeaderFramework.METHOD_HEAD, arg, session);
// we now know the HTTP version. depending on that, we read the header // we now know the HTTP version. depending on that, we read the header
final String httpVersion = prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); String httpVersion = (String) prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = HeaderFramework.HTTP_VERSION_0_9;
final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9)) final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9))
? new RequestHeader(reverseMappingCache) ? new RequestHeader(reverseMappingCache)
: readHeader(prop,session); : readHeader(prop,session);
@ -458,7 +457,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
handlePersistentConnection(header, prop); handlePersistentConnection(header, prop);
// return multi-line message // return multi-line message
if (prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) { if (prop.get(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) {
// pass to server // pass to server
if (allowServer(session)) { if (allowServer(session)) {
HTTPDFileHandler.doHead(prop, header, session.out); HTTPDFileHandler.doHead(prop, header, session.out);
@ -478,7 +477,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return serverCore.TERMINATE_CONNECTION; return serverCore.TERMINATE_CONNECTION;
} }
} }
return prop.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; return prop.get(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION;
} catch (final Exception e) { } catch (final Exception e) {
logUnexpectedError(e, session.userAddress.getHostAddress()); logUnexpectedError(e, session.userAddress.getHostAddress());
return serverCore.TERMINATE_CONNECTION; return serverCore.TERMINATE_CONNECTION;
@ -488,10 +487,10 @@ public final class HTTPDemon implements serverHandler, Cloneable {
public Boolean POST(final String arg, final Session session) { public Boolean POST(final String arg, final Session session) {
//System.out.println("POST " + arg); //System.out.println("POST " + arg);
try { try {
final Properties prop = parseRequestLine(HeaderFramework.METHOD_POST, arg, session); final HashMap<String, Object> prop = parseRequestLine(HeaderFramework.METHOD_POST, arg, session);
// we now know the HTTP version. depending on that, we read the header // we now know the HTTP version. depending on that, we read the header
final String httpVersion = prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); String httpVersion = (String) prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = HeaderFramework.HTTP_VERSION_0_9;
final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9)) final RequestHeader header = (httpVersion.equals(HeaderFramework.HTTP_VERSION_0_9))
? new RequestHeader(reverseMappingCache) ? new RequestHeader(reverseMappingCache)
: readHeader(prop, session); : readHeader(prop, session);
@ -523,7 +522,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
handlePersistentConnection(header, prop); handlePersistentConnection(header, prop);
// return multi-line message // return multi-line message
if (prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) { if (prop.get(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) {
// pass to server // pass to server
if (allowServer(session)) { if (allowServer(session)) {
HTTPDFileHandler.doPost(prop, header, session.out, sessionIn); HTTPDFileHandler.doPost(prop, header, session.out, sessionIn);
@ -545,27 +544,27 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
if (sessionIn instanceof ChunkedInputStream) sessionIn.close(); // read to end, but do not close the stream (maybe HTTP/1.1 persistent) if (sessionIn instanceof ChunkedInputStream) sessionIn.close(); // read to end, but do not close the stream (maybe HTTP/1.1 persistent)
//return serverCore.RESUME_CONNECTION; //return serverCore.RESUME_CONNECTION;
return prop.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION; return prop.get(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") ? serverCore.RESUME_CONNECTION : serverCore.TERMINATE_CONNECTION;
} catch (final Exception e) { } catch (final Exception e) {
logUnexpectedError(e, session.userAddress.getHostAddress()); logUnexpectedError(e, session.userAddress.getHostAddress());
return serverCore.TERMINATE_CONNECTION; return serverCore.TERMINATE_CONNECTION;
} }
} }
public static void handleTransparentProxySupport(final RequestHeader header, final Properties prop, final String virtualHost, final boolean isTransparentProxy) { public static void handleTransparentProxySupport(final RequestHeader header, final HashMap<String, Object> prop, final String virtualHost, final boolean isTransparentProxy) {
// transparent proxy support is only available for http 1.0 and above connections // transparent proxy support is only available for http 1.0 and above connections
if (prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, "HTTP/0.9").equals("HTTP/0.9")) return; if (prop.containsKey(HeaderFramework.CONNECTION_PROP_HTTP_VER) && prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER).equals("HTTP/0.9")) return;
// if the transparent proxy support was disabled, we have nothing todo here ... // if the transparent proxy support was disabled, we have nothing todo here ...
if (!(isTransparentProxy && header.containsKey(HeaderFramework.HOST))) return; if (!(isTransparentProxy && header.containsKey(HeaderFramework.HOST))) return;
// we only need to do the transparent proxy support if the request URL didn't contain the hostname // we only need to do the transparent proxy support if the request URL didn't contain the hostname
// and therefor was set to virtualHost by function parseQuery() // and therefor was set to virtualHost by function parseQuery()
if (!prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) return; if (!prop.get(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) return;
// TODO: we could have problems with connections from extern here ... // TODO: we could have problems with connections from extern here ...
final String dstHostSocket = header.get(HeaderFramework.HOST); final String dstHostSocket = header.get(HeaderFramework.HOST);
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST,(HTTPDemon.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket)); prop.put(HeaderFramework.CONNECTION_PROP_HOST,(HTTPDemon.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
} }
public Boolean CONNECT(String arg, final Session session) throws IOException { public Boolean CONNECT(String arg, final Session session) throws IOException {
@ -582,11 +581,11 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} else { } else {
httpVersion = "HTTP/1.0"; httpVersion = "HTTP/1.0";
} }
Properties prop = new Properties(); HashMap<String, Object> prop = new HashMap<String, Object>();
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, httpVersion); prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, httpVersion);
// parse hostname and port // parse hostname and port
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, arg); prop.put(HeaderFramework.CONNECTION_PROP_HOST, arg);
pos = arg.indexOf(':'); pos = arg.indexOf(':');
int port = 443; int port = 443;
if (pos >= 0) { if (pos >= 0) {
@ -595,11 +594,11 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
// setting other connection properties // setting other connection properties
prop.setProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP, session.userAddress.isAnyLocalAddress() ? "localhost" : session.userAddress.getHostAddress()); prop.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, session.userAddress.isAnyLocalAddress() ? "localhost" : session.userAddress.getHostAddress());
prop.setProperty(HeaderFramework.CONNECTION_PROP_METHOD, HeaderFramework.METHOD_CONNECT); prop.put(HeaderFramework.CONNECTION_PROP_METHOD, HeaderFramework.METHOD_CONNECT);
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, "/"); prop.put(HeaderFramework.CONNECTION_PROP_PATH, "/");
prop.setProperty(HeaderFramework.CONNECTION_PROP_EXT, ""); prop.put(HeaderFramework.CONNECTION_PROP_EXT, "");
prop.setProperty(HeaderFramework.CONNECTION_PROP_URL, ""); prop.put(HeaderFramework.CONNECTION_PROP_URL, "");
// parse remaining lines // parse remaining lines
final RequestHeader header = readHeader(prop,session); final RequestHeader header = readHeader(prop,session);
@ -630,24 +629,24 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return serverCore.TERMINATE_CONNECTION; return serverCore.TERMINATE_CONNECTION;
} }
private final Properties parseRequestLine(final String cmd, final String s, final Session session) { private final HashMap<String, Object> parseRequestLine(final String cmd, final String s, final Session session) {
// parsing the header // parsing the header
final Properties p = parseRequestLine(cmd, s, virtualHost); final HashMap<String, Object> p = parseRequestLine(cmd, s, virtualHost);
// track the request // track the request
final String path = p.getProperty(HeaderFramework.CONNECTION_PROP_URL); final String path = (String) p.get(HeaderFramework.CONNECTION_PROP_URL);
final String args = p.getProperty(HeaderFramework.CONNECTION_PROP_ARGS, ""); String args = (String) p.get(HeaderFramework.CONNECTION_PROP_ARGS); if (args == null) args = "";
switchboard.track(session.userAddress.getHostAddress(), (args.length() > 0) ? path + "?" + args : path); switchboard.track(session.userAddress.getHostAddress(), (args.length() > 0) ? path + "?" + args : path);
// reseting the empty request counter // reseting the empty request counter
this.emptyRequestCount = 0; this.emptyRequestCount = 0;
// counting the amount of received requests within this permanent connection // counting the amount of received requests within this permanent connection
p.setProperty(HeaderFramework.CONNECTION_PROP_KEEP_ALIVE_COUNT, Integer.toString(++this.keepAliveRequestCount)); p.put(HeaderFramework.CONNECTION_PROP_KEEP_ALIVE_COUNT, Integer.toString(++this.keepAliveRequestCount));
// setting the client-IP // setting the client-IP
p.setProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP, session.userAddress.getHostAddress()); p.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, session.userAddress.getHostAddress());
return p; return p;
} }
@ -953,7 +952,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondError( public static final void sendRespondError(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
final int errorcase, final int errorcase,
final int httpStatusCode, final int httpStatusCode,
@ -976,7 +975,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondError( public static final void sendRespondError(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
final int httpStatusCode, final int httpStatusCode,
final String httpStatusText, final String httpStatusText,
@ -999,7 +998,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondError( public static final void sendRespondError(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
final int errorcase, final int errorcase,
final int httpStatusCode, final int httpStatusCode,
@ -1015,7 +1014,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
ByteArrayOutputStream o = null; ByteArrayOutputStream o = null;
try { try {
// setting the proper http status message // setting the proper http status message
final String httpVersion = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER,"HTTP/1.1"); String httpVersion = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = "HTTP/1.1";
if ((httpStatusText == null)||(httpStatusText.length()==0)) { if ((httpStatusText == null)||(httpStatusText.length()==0)) {
if (httpVersion.equals("HTTP/1.0") && HeaderFramework.http1_0.containsKey(Integer.toString(httpStatusCode))) if (httpVersion.equals("HTTP/1.0") && HeaderFramework.http1_0.containsKey(Integer.toString(httpStatusCode)))
httpStatusText = HeaderFramework.http1_0.get(Integer.toString(httpStatusCode)); httpStatusText = HeaderFramework.http1_0.get(Integer.toString(httpStatusCode));
@ -1025,10 +1024,10 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
// generating the desired request url // generating the desired request url
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH,"/"); String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); if (path == null) path = "/";
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS);
final String method = conProp.getProperty(HeaderFramework.CONNECTION_PROP_METHOD); final String method = (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD);
final int port; final int port;
final int pos = host.indexOf(':'); final int pos = host.indexOf(':');
@ -1049,7 +1048,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// set rewrite values // set rewrite values
final serverObjects tp = new serverObjects(); final serverObjects tp = new serverObjects();
final String clientIP = conProp.getProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1"); String clientIP = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); if (clientIP == null) clientIP = "127.0.0.1";
// check if ip is local ip address // check if ip is local ip address
final InetAddress hostAddress = Domains.dnsResolve(clientIP); final InetAddress hostAddress = Domains.dnsResolve(clientIP);
@ -1067,7 +1066,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
tp.put("peerName", (getAlternativeResolver() == null) ? "" : getAlternativeResolver().myName()); tp.put("peerName", (getAlternativeResolver() == null) ? "" : getAlternativeResolver().myName());
tp.put("errorMessageType", errorcase); tp.put("errorMessageType", errorcase);
tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText); tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText);
tp.put("requestMethod", conProp.getProperty(HeaderFramework.CONNECTION_PROP_METHOD)); tp.put("requestMethod", (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD));
tp.put("requestURL", urlString); tp.put("requestURL", urlString);
switch (errorcase) { switch (errorcase) {
@ -1136,7 +1135,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondHeader( public static final void sendRespondHeader(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
final String httpVersion, final String httpVersion,
final int httpStatusCode, final int httpStatusCode,
@ -1151,14 +1150,14 @@ public final class HTTPDemon implements serverHandler, Cloneable {
final boolean nocache final boolean nocache
) throws IOException { ) throws IOException {
final String reqMethod = conProp.getProperty(HeaderFramework.CONNECTION_PROP_METHOD); final String reqMethod = (String) conProp.get(HeaderFramework.CONNECTION_PROP_METHOD);
if ((transferEnc != null) && !httpVersion.equals(HeaderFramework.HTTP_VERSION_1_1)) { if ((transferEnc != null) && !httpVersion.equals(HeaderFramework.HTTP_VERSION_1_1)) {
throw new IllegalArgumentException("Transfer encoding is only supported for http/1.1 connections. The current connection version is " + httpVersion); throw new IllegalArgumentException("Transfer encoding is only supported for http/1.1 connections. The current connection version is " + httpVersion);
} }
if (!reqMethod.equals(HeaderFramework.METHOD_HEAD)){ if (!reqMethod.equals(HeaderFramework.METHOD_HEAD)){
if (!conProp.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT,"close").equals("close") && if (!"close".equals(conProp.get(HeaderFramework.CONNECTION_PROP_PERSISTENT)) &&
transferEnc == null && contentLength < 0) { transferEnc == null && contentLength < 0) {
throw new IllegalArgumentException("Message MUST contain a Content-Length or a non-identity transfer-coding header field."); throw new IllegalArgumentException("Message MUST contain a Content-Length or a non-identity transfer-coding header field.");
} }
@ -1197,7 +1196,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondHeader( public static final void sendRespondHeader(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
final String httpVersion, final String httpVersion,
final int httpStatusCode, final int httpStatusCode,
@ -1207,7 +1206,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static final void sendRespondHeader( public static final void sendRespondHeader(
final Properties conProp, final HashMap<String, Object> conProp,
final OutputStream respond, final OutputStream respond,
String httpVersion, String httpVersion,
final int httpStatusCode, final int httpStatusCode,
@ -1217,7 +1216,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
if (respond == null) throw new NullPointerException("The outputstream must not be null."); if (respond == null) throw new NullPointerException("The outputstream must not be null.");
if (conProp == null) throw new NullPointerException("The connection property structure must not be null."); if (conProp == null) throw new NullPointerException("The connection property structure must not be null.");
if (httpVersion == null) httpVersion = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER,HeaderFramework.HTTP_VERSION_1_1); if (httpVersion == null) httpVersion = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = HeaderFramework.HTTP_VERSION_1_1;
if (responseHeader == null) responseHeader = new ResponseHeader(); if (responseHeader == null) responseHeader = new ResponseHeader();
try { try {
@ -1244,19 +1243,19 @@ public final class HTTPDemon implements serverHandler, Cloneable {
if (!responseHeader.containsKey(HeaderFramework.CONTENT_TYPE)) if (!responseHeader.containsKey(HeaderFramework.CONTENT_TYPE))
responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/html; charset=UTF-8"); // fix this responseHeader.put(HeaderFramework.CONTENT_TYPE, "text/html; charset=UTF-8"); // fix this
if (!responseHeader.containsKey(RequestHeader.CONNECTION) && conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT)) if (!responseHeader.containsKey(RequestHeader.CONNECTION) && conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT))
responseHeader.put(RequestHeader.CONNECTION, conProp.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT)); responseHeader.put(RequestHeader.CONNECTION, (String) conProp.get(HeaderFramework.CONNECTION_PROP_PERSISTENT));
if (!responseHeader.containsKey(RequestHeader.PROXY_CONNECTION) && conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT)) if (!responseHeader.containsKey(RequestHeader.PROXY_CONNECTION) && conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT))
responseHeader.put(RequestHeader.PROXY_CONNECTION, conProp.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT)); responseHeader.put(RequestHeader.PROXY_CONNECTION, (String) conProp.get(HeaderFramework.CONNECTION_PROP_PERSISTENT));
if (conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT) && if (conProp.containsKey(HeaderFramework.CONNECTION_PROP_PERSISTENT) &&
conProp.getProperty(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") && conProp.get(HeaderFramework.CONNECTION_PROP_PERSISTENT).equals("keep-alive") &&
!responseHeader.containsKey(HeaderFramework.TRANSFER_ENCODING) && !responseHeader.containsKey(HeaderFramework.TRANSFER_ENCODING) &&
!responseHeader.containsKey(HeaderFramework.CONTENT_LENGTH)) !responseHeader.containsKey(HeaderFramework.CONTENT_LENGTH))
responseHeader.put(HeaderFramework.CONTENT_LENGTH, "0"); responseHeader.put(HeaderFramework.CONTENT_LENGTH, "0");
// adding some yacy specific headers // adding some yacy specific headers
responseHeader.put(HeaderFramework.X_YACY_KEEP_ALIVE_REQUEST_COUNT,conProp.getProperty(HeaderFramework.CONNECTION_PROP_KEEP_ALIVE_COUNT)); responseHeader.put(HeaderFramework.X_YACY_KEEP_ALIVE_REQUEST_COUNT,(String) conProp.get(HeaderFramework.CONNECTION_PROP_KEEP_ALIVE_COUNT));
responseHeader.put(HeaderFramework.X_YACY_ORIGINAL_REQUEST_LINE,conProp.getProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE)); responseHeader.put(HeaderFramework.X_YACY_ORIGINAL_REQUEST_LINE,(String) conProp.get(HeaderFramework.CONNECTION_PROP_REQUESTLINE));
//responseHeader.put(HeaderFramework.X_YACY_PREVIOUS_REQUEST_LINE,conProp.getProperty(HeaderFramework.CONNECTION_PROP_PREV_REQUESTLINE)); //responseHeader.put(HeaderFramework.X_YACY_PREVIOUS_REQUEST_LINE,conProp.getProperty(HeaderFramework.CONNECTION_PROP_PREV_REQUESTLINE));
//read custom headers //read custom headers
@ -1375,7 +1374,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} }
public static RequestHeader readHeader(final Properties prop, final serverCore.Session theSession) throws IOException { public static RequestHeader readHeader(final HashMap<String, Object> prop, final serverCore.Session theSession) throws IOException {
// reading all headers // reading all headers
final RequestHeader header = new RequestHeader(HTTPDemon.reverseMappingCache); final RequestHeader header = new RequestHeader(HTTPDemon.reverseMappingCache);
@ -1393,7 +1392,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
/* /*
* doing some header validation here ... * doing some header validation here ...
*/ */
final String httpVersion = prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, "HTTP/0.9"); String httpVersion = (String) prop.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); if (httpVersion == null) httpVersion = "HTTP/0.9";
if (httpVersion.equals("HTTP/1.1") && !header.containsKey(HeaderFramework.HOST)) { if (httpVersion.equals("HTTP/1.1") && !header.containsKey(HeaderFramework.HOST)) {
// the HTTP/1.1 specification requires that an HTTP/1.1 server must reject any // the HTTP/1.1 specification requires that an HTTP/1.1 server must reject any
// HTTP/1.1 message that does not contain a Host header. // HTTP/1.1 message that does not contain a Host header.
@ -1415,20 +1414,20 @@ public final class HTTPDemon implements serverHandler, Cloneable {
private static final Pattern P_60 = Pattern.compile("`", Pattern.LITERAL); private static final Pattern P_60 = Pattern.compile("`", Pattern.LITERAL);
public static Properties parseRequestLine(final String cmd, String args, final String virtualHost) { public static HashMap<String, Object> parseRequestLine(final String cmd, String args, final String virtualHost) {
final Properties prop = new Properties(); final HashMap<String, Object> prop = new HashMap<String, Object>(); // we can use a non-synchronized data structure here
// storing informations about the request // storing informations about the request
prop.setProperty(HeaderFramework.CONNECTION_PROP_METHOD, cmd); prop.put(HeaderFramework.CONNECTION_PROP_METHOD, cmd);
prop.setProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE, cmd + " " + args); prop.put(HeaderFramework.CONNECTION_PROP_REQUESTLINE, cmd + " " + args);
// this parses a whole URL // this parses a whole URL
if (args.isEmpty()) { if (args.isEmpty()) {
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost); prop.put(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, "/"); prop.put(HeaderFramework.CONNECTION_PROP_PATH, "/");
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
prop.setProperty(HeaderFramework.CONNECTION_PROP_EXT, ""); prop.put(HeaderFramework.CONNECTION_PROP_EXT, "");
return prop; return prop;
} }
@ -1436,11 +1435,11 @@ public final class HTTPDemon implements serverHandler, Cloneable {
int sep = args.lastIndexOf(' '); int sep = args.lastIndexOf(' ');
if ((sep >= 0) && (args.substring(sep + 1).toLowerCase().startsWith("http/"))) { if ((sep >= 0) && (args.substring(sep + 1).toLowerCase().startsWith("http/"))) {
// HTTP version is given // HTTP version is given
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, args.substring(sep + 1).trim()); prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, args.substring(sep + 1).trim());
args = args.substring(0, sep).trim(); // cut off HTTP version mark args = args.substring(0, sep).trim(); // cut off HTTP version mark
} else { } else {
// HTTP version is not given, it will be treated as ver 0.9 // HTTP version is not given, it will be treated as ver 0.9
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
} }
// replacing spaces in the url string correctly // replacing spaces in the url string correctly
@ -1467,9 +1466,9 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} else { } else {
argsString = ""; argsString = "";
} }
prop.setProperty(HeaderFramework.CONNECTION_PROP_URL, args); // store URL prop.put(HeaderFramework.CONNECTION_PROP_URL, args); // store URL
if (!argsString.isEmpty()) { if (!argsString.isEmpty()) {
prop.setProperty(HeaderFramework.CONNECTION_PROP_ARGS, argsString); prop.put(HeaderFramework.CONNECTION_PROP_ARGS, argsString);
} // store arguments in original form } // store arguments in original form
// finally find host string // finally find host string
@ -1484,13 +1483,13 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// we are lazy and guess that it means // we are lazy and guess that it means
// /index.html // /index.html
// which is a localhost access to the file servlet // which is a localhost access to the file servlet
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, args); prop.put(HeaderFramework.CONNECTION_PROP_HOST, args);
path = "/"; path = "/";
} else { } else {
// THIS IS THE "GOOD" CASE // THIS IS THE "GOOD" CASE
// a perfect formulated url // a perfect formulated url
final String dstHostSocket = args.substring(0, sep); final String dstHostSocket = args.substring(0, sep);
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, (HTTPDemon.isThisHostName(dstHostSocket) ? virtualHost : dstHostSocket)); prop.put(HeaderFramework.CONNECTION_PROP_HOST, (HTTPDemon.isThisHostName(dstHostSocket) ? virtualHost : dstHostSocket));
path = args.substring(sep); // yes, including beginning "/" path = args.substring(sep); // yes, including beginning "/"
} }
} else { } else {
@ -1500,16 +1499,16 @@ public final class HTTPDemon implements serverHandler, Cloneable {
// in this case, we simulate a // in this case, we simulate a
// http://localhost/s // http://localhost/s
// access by setting a virtual host // access by setting a virtual host
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost); prop.put(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
path = args; path = args;
} else { } else {
// the client 'forgot' to set a leading '/' // the client 'forgot' to set a leading '/'
// this is the same case as above, with some lazyness // this is the same case as above, with some lazyness
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost); prop.put(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
path = "/" + args; path = "/" + args;
} }
} }
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, path); prop.put(HeaderFramework.CONNECTION_PROP_PATH, path);
// find out file extension (we already stripped ?-parameters from args) // find out file extension (we already stripped ?-parameters from args)
final String ext; final String ext;
@ -1526,7 +1525,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
} else { } else {
ext = ""; // default when no file extension ext = ""; // default when no file extension
} }
prop.setProperty(HeaderFramework.CONNECTION_PROP_EXT, ext); prop.put(HeaderFramework.CONNECTION_PROP_EXT, ext);
return prop; return prop;
} }

@ -29,7 +29,7 @@ package de.anomic.http.server;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Properties; import java.util.HashMap;
import net.yacy.cora.document.UTF8; import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.HeaderFramework;
@ -84,13 +84,13 @@ public class ServerSideIncludes {
} }
// set up virtual connection properties to call httpdFileHander.doGet() // set up virtual connection properties to call httpdFileHander.doGet()
final Properties conProp = new Properties(); final HashMap<String, Object> conProp = new HashMap<String, Object>();
final RequestHeader header = new RequestHeader(HTTPDemon.reverseMappingCache); final RequestHeader header = new RequestHeader(HTTPDemon.reverseMappingCache);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_METHOD, HeaderFramework.METHOD_GET); conProp.put(HeaderFramework.CONNECTION_PROP_METHOD, HeaderFramework.METHOD_GET);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_PATH, path); conProp.put(HeaderFramework.CONNECTION_PROP_PATH, path);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_ARGS, args); conProp.put(HeaderFramework.CONNECTION_PROP_ARGS, args);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9); conProp.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
conProp.setProperty(HeaderFramework.CONNECTION_PROP_CLIENTIP, requesthost); conProp.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, requesthost);
header.put(RequestHeader.AUTHORIZATION, authorization); header.put(RequestHeader.AUTHORIZATION, authorization);
HTTPDFileHandler.doGet(conProp, header, out); HTTPDFileHandler.doGet(conProp, header, out);
} }

@ -336,7 +336,7 @@ public class ResultFetcher {
// check if we can succeed if we try to take another url // check if we can succeed if we try to take another url
if (rankingProcess.feedingIsFinished() && rankingProcess.sizeQueue() == 0) { if (rankingProcess.feedingIsFinished() && rankingProcess.sizeQueue() == 0) {
Log.logWarning("ResultFetcher", "rankingProcess.feedingIsFinished() && rankingProcess.sizeQueue() == 0"); //Log.logWarning("ResultFetcher", "rankingProcess.feedingIsFinished() && rankingProcess.sizeQueue() == 0");
break; break;
} }

@ -29,6 +29,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -539,10 +540,10 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
theHeader.append("\r\n"); theHeader.append("\r\n");
} }
public static MultiProtocolURI getRequestURL(final Properties conProp) throws MalformedURLException { public static MultiProtocolURI getRequestURL(final HashMap<String, Object> conProp) throws MalformedURLException {
String host = conProp.getProperty(HeaderFramework.CONNECTION_PROP_HOST); String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = conProp.getProperty(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/' final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
final String args = conProp.getProperty(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
//String ip = conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer //String ip = conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
int port, pos; int port, pos;

@ -142,6 +142,7 @@ public final class FileUtils {
} }
public static int copy(final Reader source, final Writer dest) throws IOException { public static int copy(final Reader source, final Writer dest) throws IOException {
if (source == null) throw new IOException("source is null");
final char[] buffer = new char[DEFAULT_BUFFER_SIZE]; final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int count = 0; int count = 0;
int n = 0; int n = 0;
@ -153,8 +154,8 @@ public final class FileUtils {
dest.flush(); dest.flush();
} catch (final Exception e) { } catch (final Exception e) {
// an "sun.io.MalformedInputException: Missing byte-order mark" - exception may occur here // an "sun.io.MalformedInputException: Missing byte-order mark" - exception may occur here
Log.logException(e); //Log.logException(e);
throw new IOException(e.getMessage(), e); throw new IOException(e.getMessage() == null ? e.toString() : e.getMessage(), e);
} }
return count; return count;
} }

Loading…
Cancel
Save