Skip to content

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

*) Fixes for httpd - Fix for local timezone in http header See: http://www.yacy-forum.de/viewtopic.php?t=836 - Allow static content to be cached by browser See: http://www.yacy-forum.de/viewtopic.php?t=1311

hermensec1202edbe63
diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java
index 71095dc92..de148f99f 100644
--- a/source/de/anomic/http/httpc.java
+++ b/source/de/anomic/http/httpc.java
@@ -105,7 +105,7 @@ public final class httpc {
private static final String vDATE = "20040602";
private static String userAgent;
private static final int terminalMaxLength = 30000;
- private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
+ private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
/**
* This string is initialized on loading of this class and contains
* information about the current OS.
@@ -113,7 +113,10 @@ public final class httpc {
public static String systemOST;
// --- The GMT standard date format used in the HTTP protocol
- private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
+ private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+ static {
+ HTTPGMTFormatter.setTimeZone(GMTTimeZone);
+ }
static final HashMap reverseMappingCache = new HashMap();
// the dns cache
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index abbddb9e8..fd1dd2874 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -1171,14 +1171,32 @@ public final class httpd implements serverHandler {
String contentEnc,
String transferEnc
) throws IOException {
+ sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,contentType,contentLength,moddate,expires,cookie,contentEnc,transferEnc,true);
+ }
+
+ public static final void sendRespondHeader(
+ Properties conProp,
+ OutputStream respond,
+ String httpVersion,
+ int httpStatusCode,
+ String httpStatusText,
+ String contentType,
+ long contentLength,
+ Date moddate,
+ Date expires,
+ String cookie,
+ String contentEnc,
+ String transferEnc,
+ boolean nocache
+ ) throws IOException {
httpHeader headers = new httpHeader();
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.PRAGMA, "no-cache");
+ if (nocache) 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);
diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java
index 6f86e26f6..95f57d64f 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -451,6 +451,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
//File targetClass = rewriteClassFile(targetFile);
Date targetDate;
+ boolean nocache = false;
if ((targetClass != null) && (path.endsWith("png"))) {
// call an image-servlet to produce an on-the-fly - generated image
@@ -475,6 +476,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
} else {
// send an image to client
targetDate = new Date(System.currentTimeMillis());
+ nocache = true;
String mimeType = mimeTable.getProperty(targetExt,"text/html");
// generate an byte array from the generated image
@@ -486,7 +488,7 @@ 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);
+ 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);
}
@@ -583,6 +585,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
throw e;
}
targetDate = new Date(System.currentTimeMillis());
+ nocache = true;
}
// read templates
tp.putAll(templates);
@@ -667,7 +670,7 @@ 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);
+ 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);
} else {