*) 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



git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1198 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
hermens 20 years ago
parent 5a627a690f
commit 35cf6712b2

@ -1191,12 +1191,17 @@ public final class httpd implements serverHandler {
) throws IOException { ) throws IOException {
httpHeader headers = new httpHeader(); httpHeader headers = new httpHeader();
Date now = new Date(System.currentTimeMillis());
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(now));
headers.put(httpHeader.LAST_MODIFIED, httpc.dateString(moddate)); 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_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);
@ -1232,65 +1237,68 @@ public final class httpd implements serverHandler {
if (header == null) header = new httpHeader(); if (header == null) header = new httpHeader();
try { try {
if ((httpStatusText == null)||(httpStatusText.length()==0)) { // "HTTP/0.9" does not have a header in the response
if (httpVersion.equals(httpHeader.HTTP_VERSION_1_0) && httpHeader.http1_0.containsKey(Integer.toString(httpStatusCode))) if (! httpVersion.toUpperCase().equals("HTTP/0.9")) {
httpStatusText = (String) httpHeader.http1_0.get(Integer.toString(httpStatusCode)); if ((httpStatusText == null)||(httpStatusText.length()==0)) {
else if (httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && httpHeader.http1_1.containsKey(Integer.toString(httpStatusCode))) if (httpVersion.equals(httpHeader.HTTP_VERSION_1_0) && httpHeader.http1_0.containsKey(Integer.toString(httpStatusCode)))
httpStatusText = (String) httpHeader.http1_1.get(Integer.toString(httpStatusCode)); httpStatusText = (String) httpHeader.http1_0.get(Integer.toString(httpStatusCode));
else httpStatusText = "Unknown"; 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())); // prepare header
if (!header.containsKey(httpHeader.CONTENT_TYPE)) if (!header.containsKey(httpHeader.DATE))
header.put(httpHeader.CONTENT_TYPE, "text/html"); // fix this header.put(httpHeader.DATE, httpc.dateString(httpc.nowDate()));
if (!header.containsKey(httpHeader.CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT)) if (!header.containsKey(httpHeader.CONTENT_TYPE))
header.put(httpHeader.CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT)); header.put(httpHeader.CONTENT_TYPE, "text/html"); // fix this
if (!header.containsKey(httpHeader.PROXY_CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT)) if (!header.containsKey(httpHeader.CONNECTION) && conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT))
header.put(httpHeader.PROXY_CONNECTION, conProp.getProperty(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))
if (conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT) && header.put(httpHeader.PROXY_CONNECTION, conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT));
conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT).equals("keep-alive") &&
!header.containsKey(httpHeader.TRANSFER_ENCODING) && if (conProp.containsKey(httpHeader.CONNECTION_PROP_PERSISTENT) &&
!header.containsKey(httpHeader.CONTENT_LENGTH)) conProp.getProperty(httpHeader.CONNECTION_PROP_PERSISTENT).equals("keep-alive") &&
header.put(httpHeader.CONTENT_LENGTH, "0"); !header.containsKey(httpHeader.TRANSFER_ENCODING) &&
!header.containsKey(httpHeader.CONTENT_LENGTH))
// adding some yacy specific headers header.put(httpHeader.CONTENT_LENGTH, "0");
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)); // adding some yacy specific headers
header.put(httpHeader.X_YACY_PREVIOUS_REQUEST_LINE,conProp.getProperty(httpHeader.CONNECTION_PROP_PREV_REQUESTLINE)); 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 StringBuffer headerStringBuffer = new StringBuffer(560);
headerStringBuffer.append(httpVersion).append(" ")
.append(Integer.toString(httpStatusCode)).append(" ") // write status line
.append(httpStatusText).append("\r\n"); headerStringBuffer.append(httpVersion).append(" ")
.append(Integer.toString(httpStatusCode)).append(" ")
// write header .append(httpStatusText).append("\r\n");
Iterator i = header.keySet().iterator();
String key; // write header
char tag; Iterator i = header.keySet().iterator();
int count; String key;
//System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"); char tag;
while (i.hasNext()) { int count;
key = (String) i.next(); //System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");
tag = key.charAt(0); while (i.hasNext()) {
if ((tag != '*') && (tag != '#')) { // '#' in key is reserved for proxy attributes as artificial header values key = (String) i.next();
count = header.keyCount(key); tag = key.charAt(0);
for (int j = 0; j < count; j++) { if ((tag != '*') && (tag != '#')) { // '#' in key is reserved for proxy attributes as artificial header values
headerStringBuffer.append(key).append(": ").append((String) header.getSingle(key, j)).append("\r\n"); count = header.keyCount(key);
} for (int j = 0; j < count; j++) {
//System.out.println("#" + key + ": " + value); 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(); respond.flush();
conProp.put(httpHeader.CONNECTION_PROP_PROXY_RESPOND_HEADER,header); conProp.put(httpHeader.CONNECTION_PROP_PROXY_RESPOND_HEADER,header);

@ -488,9 +488,11 @@ 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, nocache); httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, result.length, targetDate, null, null, null, null, nocache);
Thread.sleep(200); // see below if (! method.equals(httpHeader.METHOD_HEAD)) {
serverFileUtils.write(result, out); Thread.sleep(200); // see below
serverFileUtils.write(result, out);
}
} }
} else if ((targetClass != null) && (path.endsWith(".stream"))) { } else if ((targetClass != null) && (path.endsWith(".stream"))) {
// call rewrite-class // call rewrite-class
@ -671,8 +673,10 @@ 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, nocache); 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 (!!) if (! method.equals(httpHeader.METHOD_HEAD)) {
serverFileUtils.write(result, out); Thread.sleep(200); // this solved the message problem (!!)
serverFileUtils.write(result, out);
}
} else { } else {
httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null); httpd.sendRespondError(conProp,out,3,404,"File not Found",null,null);
return; return;

Loading…
Cancel
Save