mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
*) 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 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1184 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
e1c2d8ec5f
commit
ec1202edbe
|
@ -105,7 +105,7 @@ public final class httpc {
|
||||||
private static final String vDATE = "20040602";
|
private static final String vDATE = "20040602";
|
||||||
private static String userAgent;
|
private static String userAgent;
|
||||||
private static final int terminalMaxLength = 30000;
|
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
|
* This string is initialized on loading of this class and contains
|
||||||
* information about the current OS.
|
* information about the current OS.
|
||||||
|
@ -113,7 +113,10 @@ public final class httpc {
|
||||||
public static String systemOST;
|
public static String systemOST;
|
||||||
|
|
||||||
// --- The GMT standard date format used in the HTTP protocol
|
// --- 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();
|
static final HashMap reverseMappingCache = new HashMap();
|
||||||
|
|
||||||
// the dns cache
|
// the dns cache
|
||||||
|
|
|
@ -1171,14 +1171,32 @@ public final class httpd implements serverHandler {
|
||||||
String contentEnc,
|
String contentEnc,
|
||||||
String transferEnc
|
String transferEnc
|
||||||
) throws IOException {
|
) 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();
|
httpHeader headers = new httpHeader();
|
||||||
|
|
||||||
headers.put(httpHeader.SERVER, "AnomicHTTPD (www.anomic.de)");
|
headers.put(httpHeader.SERVER, "AnomicHTTPD (www.anomic.de)");
|
||||||
headers.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));
|
headers.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));
|
||||||
headers.put(httpHeader.LAST_MODIFIED, httpc.dateString(moddate));
|
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_TYPE, (contentType == null)? "text/html" : contentType);
|
||||||
if (contentLength > 0) headers.put(httpHeader.CONTENT_LENGTH, Long.toString(contentLength));
|
if (contentLength > 0) headers.put(httpHeader.CONTENT_LENGTH, Long.toString(contentLength));
|
||||||
if (cookie != null) headers.put(httpHeader.SET_COOKIE, cookie);
|
if (cookie != null) headers.put(httpHeader.SET_COOKIE, cookie);
|
||||||
|
|
|
@ -451,6 +451,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
|
||||||
|
|
||||||
//File targetClass = rewriteClassFile(targetFile);
|
//File targetClass = rewriteClassFile(targetFile);
|
||||||
Date targetDate;
|
Date targetDate;
|
||||||
|
boolean nocache = false;
|
||||||
|
|
||||||
if ((targetClass != null) && (path.endsWith("png"))) {
|
if ((targetClass != null) && (path.endsWith("png"))) {
|
||||||
// call an image-servlet to produce an on-the-fly - generated image
|
// 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 {
|
} else {
|
||||||
// send an image to client
|
// send an image to client
|
||||||
targetDate = new Date(System.currentTimeMillis());
|
targetDate = new Date(System.currentTimeMillis());
|
||||||
|
nocache = true;
|
||||||
String mimeType = mimeTable.getProperty(targetExt,"text/html");
|
String mimeType = mimeTable.getProperty(targetExt,"text/html");
|
||||||
|
|
||||||
// generate an byte array from the generated image
|
// generate an byte array from the generated image
|
||||||
|
@ -486,7 +488,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
|
||||||
baos.close(); baos = null;
|
baos.close(); baos = null;
|
||||||
|
|
||||||
// write the array to the client
|
// 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
|
Thread.sleep(200); // see below
|
||||||
serverFileUtils.write(result, out);
|
serverFileUtils.write(result, out);
|
||||||
}
|
}
|
||||||
|
@ -583,6 +585,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
targetDate = new Date(System.currentTimeMillis());
|
targetDate = new Date(System.currentTimeMillis());
|
||||||
|
nocache = true;
|
||||||
}
|
}
|
||||||
// read templates
|
// read templates
|
||||||
tp.putAll(templates);
|
tp.putAll(templates);
|
||||||
|
@ -667,7 +670,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the array to the client
|
// 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 (!!)
|
Thread.sleep(200); // this solved the message problem (!!)
|
||||||
serverFileUtils.write(result, out);
|
serverFileUtils.write(result, out);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user