Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) moving constants (see last commit) to proper httpHeader class *) migrating fileHandler + proxyHandler to use constants instead of hardcoded values
theli4dd387aae99c
diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.javaindex e36a00311..c5d80d238 100644--- a/source/de/anomic/http/httpHeader.java+++ b/source/de/anomic/http/httpHeader.java@@ -71,6 +71,45 @@ import de.anomic.server.serverLog;public final class httpHeader extends TreeMap implements Map {++ /* =============================================================+ * Constants defining http header names+ * ============================================================= */+ public static final String ACCEPT = "Accept";+ public static final String ACCEPT_CHARSET = "Accept-Charset";+ public static final String ACCEPT_LANGUAGE = "Accept-Language";+ public static final String KEEP_ALIVE = "Keep-Alive";+ public static final String USER_AGENT = "User-Agent";+ public static final String HOST = "Host";+ public static final String CONNECTION = "Connection";+ public static final String REFERER = "Referer";+ public static final String ACCEPT_ENCODING = "Accept-Encoding";+ public static final String CONTENT_LENGTH = "CONTENT-LENGTH";+ public static final String CONTENT_TYPE = "CONTENT-TYPE";+ public static final String AUTHORIZATION = "Authorization";+ public static final String WWW_AUTHENTICATE = "WWW-Authenticate";+ public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";+ public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate";+ public static final String DATE = "Date";+ public static final String SERVER = "Server";+ public static final String LAST_MODIFIED = "Last-modified";+ public static final String PRAGMA = "Pragma";+ public static final String SET_COOKIE = "Set-Cookie";+ public static final String IF_MODIFIED_SINCE = "IF-MODIFIED-SINCE";+ public static final String COOKIE = "Cookie";+ public static final String EXPIRES = "Expires";+ public static final String CONTENT_ENCODING = "CONTENT-ENCODING";++ /* =============================================================+ * Constants defining http methods+ * ============================================================= */+ public static final String METHOD_GET = "GET";+ public static final String METHOD_HEAD = "HEAD";+ public static final String METHOD_POST = "POST";+ public static final String METHOD_CONNECT = "CONNECT";+++private final HashMap reverseMappingCache;private static Collator insensitiveCollator = Collator.getInstance(Locale.US);@@ -200,6 +239,7 @@ public final class httpHeader extends TreeMap implements Map {private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");private static SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");private static SimpleDateFormat EMLFormatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.US);+public static Date parseHTTPDate(String s) {if ((s == null) || (s.length() < 9)) return new Date();@@ -239,23 +279,23 @@ public final class httpHeader extends TreeMap implements Map {}public String mime() {- return (String) get("CONTENT-TYPE", "application/octet-stream");+ return (String) get(httpHeader.CONTENT_TYPE, "application/octet-stream");}public Date date() {- return headerDate("Date");+ return headerDate(httpHeader.DATE);}public Date expires() {- return headerDate("Expires");+ return headerDate(httpHeader.EXPIRES);}public Date lastModified() {- return headerDate("Last-modified");+ return headerDate(httpHeader.LAST_MODIFIED);}public Date ifModifiedSince() {- return headerDate("IF-MODIFIED-SINCE");+ return headerDate(httpHeader.IF_MODIFIED_SINCE);}public long age() {@@ -264,9 +304,9 @@ public final class httpHeader extends TreeMap implements Map {}public long contentLength() {- if (containsKey("CONTENT-LENGTH")) {+ if (containsKey(httpHeader.CONTENT_LENGTH)) {try {- return Long.parseLong((String) get("CONTENT-LENGTH"));+ return Long.parseLong((String) get(httpHeader.CONTENT_LENGTH));} catch (NumberFormatException e) {return -1;}@@ -276,8 +316,8 @@ public final class httpHeader extends TreeMap implements Map {}public boolean gzip() {- return ((containsKey("CONTENT-ENCODING")) &&- (((String) get("CONTENT-ENCODING")).toUpperCase().startsWith("GZIP")));+ return ((containsKey(httpHeader.CONTENT_ENCODING)) &&+ (((String) get(httpHeader.CONTENT_ENCODING)).toUpperCase().startsWith("GZIP")));}/*public static void main(String[] args) {diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.javaindex 106674c23..22a26aceb 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -586,36 +586,36 @@ public final class httpc {if (header == null) header = new httpHeader();// set some standard values- if (!(header.containsKey(http.HEADER_ACCEPT)))- header.put(http.HEADER_ACCEPT, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");- if (!(header.containsKey(http.HEADER_ACCEPT_CHARSET)))- header.put(http.HEADER_ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");- if (!(header.containsKey(http.HEADER_ACCEPT_LANGUAGE)))- header.put(http.HEADER_ACCEPT_LANGUAGE, "en-us,en;q=0.5");- if (!(header.containsKey(http.HEADER_KEEP_ALIVE)))- header.put(http.HEADER_KEEP_ALIVE, "300");+ if (!(header.containsKey(httpHeader.ACCEPT)))+ header.put(httpHeader.ACCEPT, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");+ if (!(header.containsKey(httpHeader.ACCEPT_CHARSET)))+ header.put(httpHeader.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");+ if (!(header.containsKey(httpHeader.ACCEPT_LANGUAGE)))+ header.put(httpHeader.ACCEPT_LANGUAGE, "en-us,en;q=0.5");+ if (!(header.containsKey(httpHeader.KEEP_ALIVE)))+ header.put(httpHeader.KEEP_ALIVE, "300");// set user agent. The user agent is only set if the value does not yet exists.// this gives callers the opportunity, to change the user agent themselves, and// it will not be changed.- if (!(header.containsKey(http.HEADER_USER_AGENT))) header.put(http.HEADER_USER_AGENT, userAgent);+ if (!(header.containsKey(httpHeader.USER_AGENT))) header.put(httpHeader.USER_AGENT, userAgent);// set the host attribute. This is in particular necessary, if we contact another proxy// the host is mandatory, if we use HTTP/1.1- if (!(header.containsKey(http.HEADER_HOST))) {+ if (!(header.containsKey(httpHeader.HOST))) {if (this.remoteProxyUse)- header.put(http.HEADER_HOST, savedRemoteHost);+ header.put(httpHeader.HOST, savedRemoteHost);else- header.put(http.HEADER_HOST, this.host);+ header.put(httpHeader.HOST, this.host);}- if (!(header.containsKey(http.HEADER_CONNECTION))) {- header.put(http.HEADER_CONNECTION, "close");+ if (!(header.containsKey(httpHeader.CONNECTION))) {+ header.put(httpHeader.CONNECTION, "close");}// advertise a little bit...- if ((!(header.containsKey(http.HEADER_REFERER))) || (((String) header.get(http.HEADER_REFERER)).trim().length() == 0)) {- header.put(http.HEADER_REFERER,+ if ((!(header.containsKey(httpHeader.REFERER))) || (((String) header.get(httpHeader.REFERER)).trim().length() == 0)) {+ header.put(httpHeader.REFERER,(((System.currentTimeMillis() >> 10) & 1) == 0) ?"http://www.anomic.de" :"http://www.yacy.net/yacy");@@ -623,30 +623,30 @@ public final class httpc {// stimulate zipping or not// we can unzip, and we will return it always as unzipped, unless not wanted- if (header.containsKey(http.HEADER_ACCEPT_ENCODING)) {- String encoding = (String) header.get(http.HEADER_ACCEPT_ENCODING);+ if (header.containsKey(httpHeader.ACCEPT_ENCODING)) {+ String encoding = (String) header.get(httpHeader.ACCEPT_ENCODING);if (zipped) {if (encoding.indexOf("gzip") < 0) {// add the gzip encoding//System.out.println("!!! adding gzip encoding");- header.put(http.HEADER_ACCEPT_ENCODING, "gzip,deflate" + ((encoding.length() == 0) ? "" : (";" + encoding)));+ header.put(httpHeader.ACCEPT_ENCODING, "gzip,deflate" + ((encoding.length() == 0) ? "" : (";" + encoding)));}} else {int pos = encoding.indexOf("gzip");if (pos >= 0) {// remove the gzip encoding//System.out.println("!!! removing gzip encoding");- header.put(http.HEADER_ACCEPT_ENCODING, encoding.substring(0, pos) + encoding.substring(pos + 4));+ header.put(httpHeader.ACCEPT_ENCODING, encoding.substring(0, pos) + encoding.substring(pos + 4));}}} else {- if (zipped) header.put(http.HEADER_ACCEPT_ENCODING, "gzip,deflate");+ if (zipped) header.put(httpHeader.ACCEPT_ENCODING, "gzip,deflate");}//header = new httpHeader(); header.put("Host", this.host); // debug// send request- if ((this.remoteProxyUse) && (!(method.equals(http.METHOD_CONNECT))))+ if ((this.remoteProxyUse) && (!(method.equals(httpHeader.METHOD_CONNECT))))path = "http://" + this.savedRemoteHost + path;serverCore.send(clientOutput, method + " " + path + " HTTP/1.0"); // if set to HTTP/1.1, servers give time-outs?@@ -687,7 +687,7 @@ public final class httpc {//serverLog.logDebug("HTTPC", handle + " requested GET '" + path + "', time = " + (System.currentTimeMillis() - handle));try {boolean zipped = shallTransportZipped(path);- send(http.METHOD_GET, path, requestHeader, zipped);+ send(httpHeader.METHOD_GET, path, requestHeader, zipped);response r = new response(zipped);//serverLog.logDebug("HTTPC", handle + " returned GET '" + path + "', time = " + (System.currentTimeMillis() - handle));return r;@@ -698,7 +698,7 @@ public final class httpc {public response HEAD(String path, httpHeader requestHeader) throws IOException {try {- send(http.METHOD_HEAD, path, requestHeader, false);+ send(httpHeader.METHOD_HEAD, path, requestHeader, false);return new response(false);// in this case the caller should not read the response body,// since there is none...@@ -709,9 +709,9 @@ public final class httpc {public response POST(String path, httpHeader requestHeader, InputStream ins) throws IOException {try {- send(http.METHOD_POST, path, requestHeader, false);+ send(httpHeader.METHOD_POST, path, requestHeader, false);// if there is a body to the call, we would have a CONTENT-LENGTH tag in the requestHeader- String cl = (String) requestHeader.get(http.HEADER_CONTENT_LENGTH);+ String cl = (String) requestHeader.get(httpHeader.CONTENT_LENGTH);int len, c;byte[] buffer = new byte[512];if (cl != null) {@@ -727,7 +727,7 @@ public final class httpc {clientOutput.write(buffer, 0, c);len += c;}- requestHeader.put(http.HEADER_CONTENT_LENGTH, "" + len);+ requestHeader.put(httpHeader.CONTENT_LENGTH, "" + len);}clientOutput.flush();return new response(false);@@ -738,7 +738,7 @@ public final class httpc {public response CONNECT(String host, int port, httpHeader requestHeader) throws IOException {try {- send(http.METHOD_CONNECT, host + ":" + port, requestHeader, false);+ send(httpHeader.METHOD_CONNECT, host + ":" + port, requestHeader, false);return new response(false);} catch (SocketException e) {throw new IOException(e.getMessage());@@ -750,18 +750,18 @@ public final class httpc {// make shure, the header has a boundary information like// CONTENT-TYPE=multipart/form-data; boundary=----------0xKhTmLbOuNdArYif (requestHeader == null) requestHeader = new httpHeader();- String boundary = (String) requestHeader.get(http.HEADER_CONTENT_TYPE);+ String boundary = (String) requestHeader.get(httpHeader.CONTENT_TYPE);if (boundary == null) {// create a boundaryboundary = "multipart/form-data; boundary=----------" + java.lang.System.currentTimeMillis();- requestHeader.put(http.HEADER_CONTENT_TYPE, boundary);+ requestHeader.put(httpHeader.CONTENT_TYPE, boundary);}// extract the boundary stringint pos = boundary.toUpperCase().indexOf("BOUNDARY=");if (pos < 0) {// again, create a boundaryboundary = "multipart/form-data; boundary=----------" + java.lang.System.currentTimeMillis();- requestHeader.put(http.HEADER_CONTENT_TYPE, boundary);+ requestHeader.put(httpHeader.CONTENT_TYPE, boundary);pos = boundary.indexOf("boundary=");}boundary = "--" + boundary.substring(pos + "boundary=".length());@@ -806,10 +806,10 @@ public final class httpc {byte[] body = buf.toByteArray();//System.out.println("DEBUG: PUT BODY=" + new String(body));// size of that body- requestHeader.put(http.HEADER_CONTENT_LENGTH, "" + body.length);+ requestHeader.put(httpHeader.CONTENT_LENGTH, "" + body.length);// send the header//System.out.println("header=" + requestHeader);- send(http.METHOD_POST, path, requestHeader, false);+ send(httpHeader.METHOD_POST, path, requestHeader, false);// send the body//System.out.println("body=" + buf.toString());serverCore.send(clientOutput, body);@@ -877,7 +877,7 @@ do uploadhttpHeader requestHeader) throws IOException {if (requestHeader == null) requestHeader = new httpHeader();if ((user != null) && (password != null) && (user.length() != 0)) {- requestHeader.put(http.HEADER_AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));+ requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));}httpc con = null;@@ -935,7 +935,7 @@ do uploadif (requestHeader == null) requestHeader = new httpHeader();if ((user != null) && (password != null) && (user.length() != 0)) {- requestHeader.put(http.HEADER_AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));+ requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));}httpc con = null;@@ -1003,7 +1003,7 @@ do upload// generate request headerhttpHeader requestHeader = new httpHeader();if ((user != null) && (password != null) && (user.length() != 0)) {- requestHeader.put(http.HEADER_AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));+ requestHeader.put(httpHeader.AUTHORIZATION, serverCodings.standardCoder.encodeBase64String(user + ":" + password));}// parse querydiff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex f4d360834..a6d1136cb 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -202,10 +202,10 @@ public final class httpd implements serverHandler {}private void transparentProxyHandling(httpHeader header) {- if (!(httpdProxyHandler.isTransparentProxy && header.containsKey(http.HEADER_HOST))) return;+ if (!(httpdProxyHandler.isTransparentProxy && header.containsKey(httpHeader.HOST))) return;try {- String dstHost, dstHostSocket = (String) header.get(http.HEADER_HOST);+ String dstHost, dstHostSocket = (String) header.get(httpHeader.HOST);int idx = dstHostSocket.indexOf(":");dstHost = (idx != -1) ? dstHostSocket.substring(0,idx).trim() : dstHostSocket.trim();@@ -213,11 +213,11 @@ public final class httpd implements serverHandler {if (dstPort.intValue() == 80) {if (dstHost.endsWith(".yacy")) {- this.prop.setProperty(http.HEADER_HOST,dstHostSocket);+ this.prop.setProperty(httpHeader.HOST,dstHostSocket);} else {InetAddress dstHostAddress = InetAddress.getByName(dstHost);if (!(dstHostAddress.isAnyLocalAddress() || dstHostAddress.isLoopbackAddress())) {- this.prop.setProperty(http.HEADER_HOST,dstHostSocket);+ this.prop.setProperty(httpHeader.HOST,dstHostSocket);}}}@@ -226,7 +226,7 @@ public final class httpd implements serverHandler {public Boolean GET(String arg) throws IOException {parseQuery(prop, arg);- prop.setProperty("METHOD", http.METHOD_GET);+ prop.setProperty("METHOD", httpHeader.METHOD_GET);prop.setProperty("CLIENTIP", clientIP);// we now know the HTTP version. depending on that, we read the header@@ -244,14 +244,14 @@ public final class httpd implements serverHandler {// persistent by default, but closed with the "Connection: close"// property.boolean persistent = (!((httpVersion.equals("HTTP/0.9")) || (httpVersion.equals("HTTP/1.0"))));- String connection = prop.getProperty(http.HEADER_CONNECTION, "close").toLowerCase();+ String connection = prop.getProperty(httpHeader.CONNECTION, "close").toLowerCase();if (connection.equals("close")) persistent = false;if (connection.equals("keep-alive")) persistent = true;//System.out.println("HEADER: " + header.toString());// return multi-line message- if (prop.getProperty(http.HEADER_HOST).equals(virtualHost)) {+ if (prop.getProperty(httpHeader.HOST).equals(virtualHost)) {// pass to serverif (allowServer) {if (serverAccountBase64MD5 == null) serverAccountBase64MD5 = switchboard.getConfig("serverAccountBase64MD5", "");@@ -260,11 +260,11 @@ public final class httpd implements serverHandler {if (fileHandler == null) fileHandler = new httpdFileHandler(this.switchboard);fileHandler.doGet(prop, header, this.session.out);} else {- String auth = (String) header.get(http.HEADER_AUTHORIZATION);+ String auth = (String) header.get(httpHeader.AUTHORIZATION);if (auth == null) {// authorization requested, but no authorizeation given in header. Ask for authenticate:session.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;} else if (serverAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(auth.trim().substring(6)))) {@@ -275,7 +275,7 @@ public final class httpd implements serverHandler {// wrong password given: ask for authenticate againserverLog.logInfo("HTTPD", "Wrong log-in for account 'server' in HTTPD.GET " + prop.getProperty("PATH") + " from IP " + clientIP);session.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -290,13 +290,13 @@ public final class httpd implements serverHandler {if (allowProxy) {if (proxyAccountBase64MD5 == null) proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", "");if ((proxyAccountBase64MD5.length() == 0) ||- (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(http.HEADER_PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {+ (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(httpHeader.PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {// we are authorized or no authenticate requestedif (proxyHandler != null) proxyHandler.doGet(prop, header, this.session.out);} else {// ask for authenticatesession.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +- http.HEADER_PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -311,7 +311,7 @@ public final class httpd implements serverHandler {public Boolean HEAD(String arg) throws IOException {parseQuery(prop,arg);- prop.setProperty("METHOD", http.METHOD_HEAD);+ prop.setProperty("METHOD", httpHeader.METHOD_HEAD);prop.setProperty("CLIENTIP", clientIP);// we now know the HTTP version. depending on that, we read the header@@ -325,7 +325,7 @@ public final class httpd implements serverHandler {}// return multi-line message- if (prop.getProperty(http.HEADER_HOST).equals(virtualHost)) {+ if (prop.getProperty(httpHeader.HOST).equals(virtualHost)) {// pass to serverif (allowServer) {if (serverAccountBase64MD5 == null) serverAccountBase64MD5 = switchboard.getConfig("serverAccountBase64MD5", "");@@ -334,11 +334,11 @@ public final class httpd implements serverHandler {if (fileHandler == null) fileHandler = new httpdFileHandler(this.switchboard);fileHandler.doHead(prop, header, this.session.out);} else {- String auth = (String) header.get(http.HEADER_AUTHORIZATION);+ String auth = (String) header.get(httpHeader.AUTHORIZATION);if (auth == null) {// authorization requested, but no authorizeation given in header. Ask for authenticate:session.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;} else if (serverAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(auth.trim().substring(6)))) {@@ -349,7 +349,7 @@ public final class httpd implements serverHandler {// wrong password given: ask for authenticate againserverLog.logInfo("HTTPD", "Wrong log-in for account 'server' in HTTPD.HEAD " + prop.getProperty("PATH") + " from IP " + clientIP);session.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -365,13 +365,13 @@ public final class httpd implements serverHandler {if (allowProxy) {if (proxyAccountBase64MD5 == null) proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", "");if ((proxyAccountBase64MD5.length() == 0) ||- (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(http.HEADER_PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {+ (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(httpHeader.PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {// we are authorized or no authenticate requestedif (proxyHandler != null) proxyHandler.doHead(prop, header, this.session.out);} else {// ask for authenticatesession.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +- http.HEADER_PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -387,7 +387,7 @@ public final class httpd implements serverHandler {public Boolean POST(String arg) throws IOException {parseQuery(prop, arg);- prop.setProperty("METHOD", http.METHOD_POST);+ prop.setProperty("METHOD", httpHeader.METHOD_POST);prop.setProperty("CLIENTIP", clientIP);// we now know the HTTP version. depending on that, we read the header@@ -406,7 +406,7 @@ public final class httpd implements serverHandler {if (connection.equals("keep-alive")) persistent = true;// return multi-line message- if (prop.getProperty(http.HEADER_HOST).equals(virtualHost)) {+ if (prop.getProperty(httpHeader.HOST).equals(virtualHost)) {// pass to serverif (allowServer) {if (serverAccountBase64MD5 == null) serverAccountBase64MD5 = switchboard.getConfig("serverAccountBase64MD5", "");@@ -415,11 +415,11 @@ public final class httpd implements serverHandler {if (fileHandler == null) fileHandler = new httpdFileHandler(this.switchboard);fileHandler.doPost(prop, header, this.session.out, this.session.in);} else {- String auth = (String) header.get(http.HEADER_AUTHORIZATION);+ String auth = (String) header.get(httpHeader.AUTHORIZATION);if (auth == null) {// ask for authenticatesession.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;} else if (serverAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(auth.trim().substring(6)))) {@@ -430,7 +430,7 @@ public final class httpd implements serverHandler {// wrong password given: ask for authenticate againserverLog.logInfo("HTTPD", "Wrong log-in for account 'server' in HTTPD.POST " + prop.getProperty("PATH") + " from IP " + clientIP);session.out.write((httpVersion + " 401 log-in required" + serverCore.crlfString +- http.HEADER_WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -445,13 +445,13 @@ public final class httpd implements serverHandler {if (allowProxy) {if (proxyAccountBase64MD5 == null) proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", "");if ((proxyAccountBase64MD5.length() == 0) ||- (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(http.HEADER_PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {+ (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(httpHeader.PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {// we are authorized or no authenticate requestedif (proxyHandler != null) proxyHandler.doPost(prop, header, this.session.out, this.session.in);} else {// ask for authenticatesession.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +- http.HEADER_PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());return serverCore.TERMINATE_CONNECTION;}@@ -515,13 +515,13 @@ public final class httpd implements serverHandler {if (allowProxy) {if (proxyAccountBase64MD5 == null) proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", "");if ((proxyAccountBase64MD5.length() == 0) ||- (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(http.HEADER_PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {+ (proxyAccountBase64MD5.equals(serverCodings.standardCoder.encodeMD5Hex(((String) header.get(httpHeader.PROXY_AUTHORIZATION, "xxxxxx")).trim().substring(6))))) {// we are authorized or no authenticate requestedif (proxyHandler != null) proxyHandler.doConnect(prop, header, (InputStream) this.session.in, this.session.out);} else {// ask for authenticatesession.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +- http.HEADER_PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString ++ httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString +serverCore.crlfString).getBytes());}} else {@@ -708,7 +708,7 @@ public final class httpd implements serverHandler {// we parse a multipart message and put results into the properties// find/identify boundary marker//System.out.println("DEBUG parseMultipart = <<" + new String(buffer) + ">>");- String s = (String) header.get(http.HEADER_CONTENT_TYPE);+ String s = (String) header.get(httpHeader.CONTENT_TYPE);if (s == null) return null;int q;int p = s.toLowerCase().indexOf("boundary=");diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.javaindex 70a219a43..b6557f796 100644--- a/source/de/anomic/http/httpdFileHandler.java+++ b/source/de/anomic/http/httpdFileHandler.java@@ -176,15 +176,15 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httpString cookie) throws IOException {try {out.write(("HTTP/1.1 " + retcode + " OK\r\n").getBytes());- out.write(("Server: AnomicHTTPD (www.anomic.de)\r\n").getBytes());- out.write(("Date: " + httpc.dateString(httpc.nowDate()) + "\r\n").getBytes());+ out.write((httpHeader.SERVER + ": AnomicHTTPD (www.anomic.de)\r\n").getBytes());+ out.write((httpHeader.DATE + ": " + httpc.dateString(httpc.nowDate()) + "\r\n").getBytes());if (expires != null) out.write(("Expires: " + httpc.dateString(expires) + "\r\n").getBytes());- out.write(("Content-type: " + conttype /* "image/gif", "text/html" */ + "\r\n").getBytes());- out.write(("Last-modified: " + httpc.dateString(moddate) + "\r\n").getBytes());- out.write(("Content-length: " + contlength +"\r\n").getBytes());- out.write(("Pragma: no-cache\r\n").getBytes());+ out.write((httpHeader.CONTENT_TYPE + ": " + conttype /* "image/gif", "text/html" */ + "\r\n").getBytes());+ out.write((httpHeader.LAST_MODIFIED + ": " + httpc.dateString(moddate) + "\r\n").getBytes());+ out.write((httpHeader.CONTENT_LENGTH + ": " + contlength +"\r\n").getBytes());+ out.write((httpHeader.PRAGMA + ": no-cache\r\n").getBytes());// out.write(("Accept-ranges: bytes\r\n").getBytes());- if (cookie != null) out.write(("Set-Cookie: " + cookie + "\r\n").getBytes());+ if (cookie != null) out.write((httpHeader.SET_COOKIE + ": " + cookie + "\r\n").getBytes());out.write(("\r\n").getBytes());out.flush();} catch (Exception e) {@@ -214,7 +214,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httppublic void doResponse(Properties conProp, httpHeader requestHeader, OutputStream out, PushbackInputStream body) throws IOException {- String userAgent = (String) requestHeader.get("USER-AGENT");+ String userAgent = (String) requestHeader.get(httpHeader.USER_AGENT);if (userAgent == null) userAgent = "";userAgent = userAgent.trim().toLowerCase();//userAgent = "portalmmm n400i"; // debug@@ -240,11 +240,11 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httpif ((path.endsWith("_p.html")) &&((adminAccountBase64MD5 = switchboard.getConfig("adminAccountBase64MD5", "")).length() != 0)) {// authentication required- String auth = (String) requestHeader.get("Authorization");+ String auth = (String) requestHeader.get(httpHeader.AUTHORIZATION);if (auth == null) {// no authorization given in response. Ask for thatout.write(("HTTP/1.1 401 log-in required\r\n").getBytes());- out.write(("WWW-Authenticate: Basic realm=\"admin log-in\"\r\n").getBytes());+ out.write((httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"admin log-in\"\r\n").getBytes());out.write(("\r\n").getBytes());out.flush();return;@@ -258,7 +258,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http//try {Thread.currentThread().sleep(3000);} catch (InterruptedException e) {} // add a delay to make brute-force harderserverCore.bfHost.put(clientIP, "sleep");out.write(("HTTP/1.1 401 log-in required\r\n").getBytes());- out.write(("WWW-Authenticate: Basic realm=\"admin log-in\"\r\n").getBytes());+ out.write((httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"admin log-in\"\r\n").getBytes());out.write(("\r\n").getBytes());out.flush();//System.out.println("httpd bfHosts=" + serverCore.bfHost.toString());@@ -273,12 +273,12 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http// no args here, maybe a POST with multipart extensionint length;//System.out.println("HEADER: " + requestHeader.toString()); // DEBUG- if ((method.equals("POST")) &&- (requestHeader.containsKey("CONTENT-LENGTH"))) {+ if ((method.equals(httpHeader.METHOD_POST)) &&+ (requestHeader.containsKey(httpHeader.CONTENT_LENGTH))) {// if its a POST, it can be either multipart or as args in the body- length = Integer.parseInt((String) requestHeader.get("CONTENT-LENGTH"));- if ((requestHeader.containsKey("CONTENT-TYPE")) &&- (((String) requestHeader.get("CONTENT-TYPE")).toLowerCase().startsWith("multipart"))) {+ length = Integer.parseInt((String) requestHeader.get(httpHeader.CONTENT_LENGTH));+ if ((requestHeader.containsKey(httpHeader.CONTENT_TYPE)) &&+ (((String) requestHeader.get(httpHeader.CONTENT_TYPE)).toLowerCase().startsWith("multipart"))) {// parse multipartHashMap files = httpd.parseMultipart(requestHeader, args, body, length);// integrate these files into the args@@ -396,7 +396,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httpif (tp.containsKey("AUTHENTICATE")) {String account = tp.get("AUTHENTICATE", "");out.write(("HTTP/1.1 401 log-in required\r\n").getBytes());- out.write(("WWW-Authenticate: Basic realm=\"" + account + "\"\r\n").getBytes());+ out.write((httpHeader.WWW_AUTHENTICATE + ": Basic realm=\"" + account + "\"\r\n").getBytes());out.write(("\r\n").getBytes());out.flush();return;@@ -453,7 +453,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements httpSystem.out.println("ERROR: Exception with query: " + path + "; '" + e.toString() + ":" + e.getMessage() + "'\r\n");}out.flush();- if (!(requestHeader.get("Connection", "close").equals("keep-alive"))) {+ if (!(requestHeader.get(httpHeader.CONNECTION, "close").equals("keep-alive"))) {// wait a little time until everything closes so that clients can read from the streams/socketstry {Thread.currentThread().sleep(1000);} catch (InterruptedException e) {}}diff --git a/source/de/anomic/http/httpdProxyHandler.java b/source/de/anomic/http/httpdProxyHandler.javaindex 699018049..6ab4f71ee 100644--- a/source/de/anomic/http/httpdProxyHandler.java+++ b/source/de/anomic/http/httpdProxyHandler.java@@ -273,8 +273,8 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httpath = "$Path" "=" valuedomain = "$Domain" "=" value*/- if (requestHeader.containsKey("Cookie")) {- Object[] entry = new Object[]{new Date(), clienthost, requestHeader.getMultiple("Cookie")};+ if (requestHeader.containsKey(httpHeader.COOKIE)) {+ Object[] entry = new Object[]{new Date(), clienthost, requestHeader.getMultiple(httpHeader.COOKIE)};switchboard.outgoingCookies.put(targethost, entry);}}@@ -295,8 +295,8 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt| "Secure"| "Version" "=" 1*DIGIT*/- if (respondHeader.containsKey("Set-Cookie")) {- Object[] entry = new Object[]{new Date(), targetclient, respondHeader.getMultiple("Set-Cookie")};+ if (respondHeader.containsKey(httpHeader.SET_COOKIE)) {+ Object[] entry = new Object[]{new Date(), targetclient, respondHeader.getMultiple(httpHeader.SET_COOKIE)};switchboard.incomingCookies.put(serverhost, entry);}}@@ -367,7 +367,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// set another userAgent, if not yellowlistedif ((yellowList != null) && (!(yellowList.contains(domain(hostlow))))) {// change the User-Agent- requestHeader.put("User-Agent", userAgent);+ requestHeader.put(httpHeader.USER_AGENT, userAgent);}// set a scraper and a htmlFilter@@ -424,14 +424,14 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htttry {// replace date field in old header by actual date, this is according to RFC- cachedResponseHeader.put("Date", httpc.dateString(httpc.nowDate()));+ cachedResponseHeader.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));// maybe the content length is missing- if (!(cachedResponseHeader.containsKey("CONTENT-LENGTH")))- cachedResponseHeader.put("CONTENT-LENGTH", Long.toString(cacheFile.length()));+ if (!(cachedResponseHeader.containsKey(httpHeader.CONTENT_LENGTH)))+ cachedResponseHeader.put(httpHeader.CONTENT_LENGTH, Long.toString(cacheFile.length()));// check if we can send a 304 instead the complete content- if (requestHeader.containsKey("IF-MODIFIED-SINCE")) {+ if (requestHeader.containsKey(httpHeader.IF_MODIFIED_SINCE)) {// conditional request: freshness of cache for that condition was already// checked within shallUseCache(). Now send only a 304 responselog.logInfo("CACHE HIT/304 " + cacheFile.toString());@@ -666,10 +666,10 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// return headerhttpHeader header = new httpHeader();- header.put("Date", httpc.dateString(httpc.nowDate()));- header.put("Content-type", "text/html");- header.put("Content-length", "" + o.size());- header.put("Pragma", "no-cache");+ header.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));+ header.put(httpHeader.CONTENT_TYPE, "text/html");+ header.put(httpHeader.CONTENT_LENGTH, "" + o.size());+ header.put(httpHeader.PRAGMA, "no-cache");// write the array to the clientrespondHeader(respond, origerror, header);@@ -710,7 +710,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// set another userAgent, if not yellowlistedif (!(yellowList.contains(domain(hostlow)))) {// change the User-Agent- requestHeader.put("User-Agent", userAgent);+ requestHeader.put(httpHeader.USER_AGENT, userAgent);}// resolve yacy and yacyh domains@@ -766,7 +766,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// set another userAgent, if not yellowlistedif (!(yellowList.contains(domain(host).toLowerCase()))) {// change the User-Agent- requestHeader.put("User-Agent", userAgent);+ requestHeader.put(httpHeader.USER_AGENT, userAgent);}// resolve yacy and yacyh domains@@ -967,8 +967,8 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt// prepare header//header.put("Server", "AnomicHTTPD (www.anomic.de)");- if (!(header.containsKey("date"))) header.put("Date", httpc.dateString(httpc.nowDate()));- if (!(header.containsKey("content-type"))) header.put("Content-type", "text/html"); // fix this+ if (!(header.containsKey(httpHeader.DATE))) header.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));+ if (!(header.containsKey(httpHeader.CONTENT_TYPE))) header.put(httpHeader.CONTENT_TYPE, "text/html"); // fix thisStringBuffer headerStringBuffer = new StringBuffer(200);@@ -1005,10 +1005,10 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements httprivate void textMessage(OutputStream out, String body) throws IOException {out.write(("HTTP/1.1 200 OK\r\n").getBytes());- out.write(("Server: AnomicHTTPD (www.anomic.de)\r\n").getBytes());- out.write(("Date: " + httpc.dateString(httpc.nowDate()) + "\r\n").getBytes());- out.write(("Content-type: text/plain\r\n").getBytes());- out.write(("Content-length: " + body.length() +"\r\n").getBytes());+ out.write((httpHeader.SERVER + ": AnomicHTTPD (www.anomic.de)\r\n").getBytes());+ out.write((httpHeader.DATE + ": " + httpc.dateString(httpc.nowDate()) + "\r\n").getBytes());+ out.write((httpHeader.CONTENT_TYPE + ": text/plain\r\n").getBytes());+ out.write((httpHeader.CONTENT_LENGTH + ": " + body.length() +"\r\n").getBytes());out.write(("\r\n").getBytes());out.flush();out.write(body.getBytes());