Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) fixes for httpd - don't send Body on HEAD requests - don't send a Last-modified: date, that is later then Date: - Use Cache-control instead of Pragma with HTTP/1.1 - don't send header with HTTP/0.9

hermens35cf6712b28b
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index fd1dd2874..b1f3c4dcd 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -1191,12 +1191,17 @@ public final class httpd implements serverHandler {
) throws IOException {
httpHeader headers = new httpHeader();
+ Date now = new Date(System.currentTimeMillis());
headers.put(httpHeader.SERVER, "AnomicHTTPD (www.anomic.de)");
- headers.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));
- headers.put(httpHeader.LAST_MODIFIED, httpc.dateString(moddate));
+ headers.put(httpHeader.DATE, httpc.dateString(now));
+ if (moddate.after(now)) moddate = now;
+ headers.put(httpHeader.LAST_MODIFIED, httpc.dateString(moddate));
- if (nocache) headers.put(httpHeader.PRAGMA, "no-cache");
+ if (nocache) {
+ if (httpVersion.toUpperCase().equals(headers.HTTP_VERSION_1_1)) headers.put(httpHeader.CACHE_CONTROL, "no-cache");
+ else headers.put(httpHeader.PRAGMA, "no-cache");
+ }
if (contentLength > 0) headers.put(httpHeader.CONTENT_TYPE, (contentType == null)? "text/html" : contentType);
if (contentLength > 0) headers.put(httpHeader.CONTENT_LENGTH, Long.toString(contentLength));
if (cookie != null) headers.put(httpHeader.SET_COOKIE, cookie);
@@ -1232,65 +1237,68 @@ public final class httpd implements serverHandler {
if (header == null) header = new httpHeader();
try {
- if ((httpStatusText == null)||(httpStatusText.length()==0)) {
- if (httpVersion.equals(httpHeader.HTTP_VERSION_1_0) && httpHeader.http1_0.containsKey(Integer.toString(httpStatusCode)))
- httpStatusText = (String) httpHeader.http1_0.get(Integer.toString(httpStatusCode));
- else if (httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && httpHeader.http1_1.containsKey(Integer.toString(httpStatusCode)))
- httpStatusText = (String) httpHeader.http1_1.get(Integer.toString(httpStatusCode));
- else httpStatusText = "Unknown";
- }
-
- // prepare header
- 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 this
- if (!header.containsKey(httpHeader.CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT))
- header.put(httpHeader.CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT));
- if (!header.containsKey(httpHeader.PROXY_CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT))
- header.put(httpHeader.PROXY_CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT));
-
- if (conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT) &&
- conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT).equals("keep-alive") &&
- !header.containsKey(httpHeader.TRANSFER_ENCODING) &&
- !header.containsKey(httpHeader.CONTENT_LENGTH))
- header.put(httpHeader.CONTENT_LENGTH, "0");
-
- // adding some yacy specific headers
- header.put(httpHeader.X_YACY_KEEP_ALIVE_REQUEST_COUNT,conProp.getProperty(httpHeader.CONNECTION_PROP_KEEP_ALIVE_COUNT));
- header.put(httpHeader.X_YACY_ORIGINAL_REQUEST_LINE,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE));
- header.put(httpHeader.X_YACY_PREVIOUS_REQUEST_LINE,conProp.getProperty(httpHeader.CONNECTION_PROP_PREV_REQUESTLINE));
-
-
- StringBuffer headerStringBuffer = new StringBuffer(560);
-
- // write status line
- headerStringBuffer.append(httpVersion).append(" ")
- .append(Integer.toString(httpStatusCode)).append(" ")
- .append(httpStatusText).append("\r\n");
-
- // write header
- Iterator i = header.keySet().iterator();
- String key;
- char tag;
- int count;
- //System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
- while (i.hasNext()) {
- key = (String) i.next();
- tag = key.charAt(0);
- if ((tag != '*') && (tag != '#')) { // '#' in key is reserved for proxy attributes as artificial header values
- count = header.keyCount(key);
- for (int j = 0; j < count; j++) {
- headerStringBuffer.append(key).append(": ").append((String) header.getSingle(key, j)).append("\r\n");
- }
- //System.out.println("#" + key + ": " + value);
- }
+ // "HTTP/0.9" does not have a header in the response
+ if (! httpVersion.toUpperCase().equals("HTTP/0.9")) {
+ if ((httpStatusText == null)||(httpStatusText.length()==0)) {
+ if (httpVersion.equals(httpHeader.HTTP_VERSION_1_0) && httpHeader.http1_0.containsKey(Integer.toString(httpStatusCode)))
+ httpStatusText = (String) httpHeader.http1_0.get(Integer.toString(httpStatusCode));
+ else if (httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && httpHeader.http1_1.containsKey(Integer.toString(httpStatusCode)))
+ httpStatusText = (String) httpHeader.http1_1.get(Integer.toString(httpStatusCode));
+ else httpStatusText = "Unknown";
+ }
+
+ // prepare header
+ 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 this
+ if (!header.containsKey(httpHeader.CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT))
+ header.put(httpHeader.CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT));
+ if (!header.containsKey(httpHeader.PROXY_CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT))
+ header.put(httpHeader.PROXY_CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT));
+
+ if (conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT) &&
+ conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT).equals("keep-alive") &&
+ !header.containsKey(httpHeader.TRANSFER_ENCODING) &&
+ !header.containsKey(httpHeader.CONTENT_LENGTH))
+ header.put(httpHeader.CONTENT_LENGTH, "0");
+
+ // adding some yacy specific headers
+ header.put(httpHeader.X_YACY_KEEP_ALIVE_REQUEST_COUNT,conProp.getProperty(httpHeader.CONNECTION_PROP_KEEP_ALIVE_COUNT));
+ header.put(httpHeader.X_YACY_ORIGINAL_REQUEST_LINE,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE));
+ header.put(httpHeader.X_YACY_PREVIOUS_REQUEST_LINE,conProp.getProperty(httpHeader.CONNECTION_PROP_PREV_REQUESTLINE));
+
+
+ StringBuffer headerStringBuffer = new StringBuffer(560);
+
+ // write status line
+ headerStringBuffer.append(httpVersion).append(" ")
+ .append(Integer.toString(httpStatusCode)).append(" ")
+ .append(httpStatusText).append("\r\n");
+
+ // write header
+ Iterator i = header.keySet().iterator();
+ String key;
+ char tag;
+ int count;
+ //System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
+ while (i.hasNext()) {
+ key = (String) i.next();
+ tag = key.charAt(0);
+ if ((tag != '*') && (tag != '#')) { // '#' in key is reserved for proxy attributes as artificial header values
+ count = header.keyCount(key);
+ for (int j = 0; j < count; j++) {
+ headerStringBuffer.append(key).append(": ").append((String) header.getSingle(key, j)).append("\r\n");
+ }
+ //System.out.println("#" + key + ": " + value);
+ }
+ }
+ // end header
+ headerStringBuffer.append("\r\n");
+
+ // sending headers to the client
+ respond.write(headerStringBuffer.toString().getBytes());
}
- // end header
- headerStringBuffer.append("\r\n");
-
- // sending headers to the client
- respond.write(headerStringBuffer.toString().getBytes());
respond.flush();
conProp.put(httpHeader.CONNECTION_PROP_PROXY_RESPOND_HEADER,header);
diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java
index 95f57d64f..f980be443 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -488,9 +488,11 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
baos.close(); baos = null;
// write the array to the client
- httpd.sendRespondHeader(this.connectionProperties, out, "HTTP/1.1", 200, null, mimeType, result.length, targetDate, null, null, null, null, nocache);
- Thread.sleep(200); // see below
- serverFileUtils.write(result, out);
+ httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, result.length, targetDate, null, null, null, null, nocache);
+ if (! method.equals(httpHeader.METHOD_HEAD)) {
+ Thread.sleep(200); // see below
+ serverFileUtils.write(result, out);
+ }
}
} else if ((targetClass != null) && (path.endsWith(".stream"))) {
// call rewrite-class
@@ -671,8 +673,10 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
// write the array to the client
httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, result.length, targetDate, null, null, (zipContent)?"gzip":null, null, nocache);
- Thread.sleep(200); // this solved the message problem (!!)
- serverFileUtils.write(result, out);
+ if (! method.equals(httpHeader.METHOD_HEAD)) {
+ Thread.sleep(200); // this solved the message problem (!!)
+ serverFileUtils.write(result, out);
+ }
} else {
httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);
return;