diff --git a/.classpath b/.classpath index 6ca39b8fc..e91fa83c8 100644 --- a/.classpath +++ b/.classpath @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java index 685ffbae0..bb8d3255b 100644 --- a/source/de/anomic/http/httpd.java +++ b/source/de/anomic/http/httpd.java @@ -1174,11 +1174,11 @@ public final class httpd implements serverHandler { long contentLength, Date moddate, Date expires, - String cookie, + serverObjects requestProperties, String contentEnc, String transferEnc ) throws IOException { - sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,contentType,contentLength,moddate,expires,cookie,contentEnc,transferEnc,true); + sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,contentType,contentLength,moddate,expires,requestProperties,contentEnc,transferEnc,true); } public static final void sendRespondHeader( @@ -1191,7 +1191,7 @@ public final class httpd implements serverHandler { long contentLength, Date moddate, Date expires, - String cookie, + serverObjects requestProperties, String contentEnc, String transferEnc, boolean nocache @@ -1211,12 +1211,12 @@ public final class httpd implements serverHandler { } 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); + //if (cookie != null) headers.put(httpHeader.SET_COOKIE, cookie); if (expires != null) headers.put(httpHeader.EXPIRES, httpc.dateString(expires)); if (contentEnc != null) headers.put(httpHeader.CONTENT_ENCODING, contentEnc); if (transferEnc != null) headers.put(httpHeader.TRANSFER_ENCODING, transferEnc); - sendRespondHeader(conProp, respond, httpVersion, httpStatusCode, httpStatusText, headers); + sendRespondHeader(conProp, respond, httpVersion, httpStatusCode, httpStatusText, headers,requestProperties); } public static final void sendRespondHeader( @@ -1228,15 +1228,26 @@ public final class httpd implements serverHandler { ) throws IOException { sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,null,header); } - + /*This we need because the interface has changed*/ public static final void sendRespondHeader( - Properties conProp, + Properties conProp, OutputStream respond, String httpVersion, int httpStatusCode, String httpStatusText, httpHeader header ) throws IOException { + sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,null,header,null); + } + public static final void sendRespondHeader( + Properties conProp, + OutputStream respond, + String httpVersion, + int httpStatusCode, + String httpStatusText, + httpHeader header, + serverObjects requestProperties + ) throws IOException { if (respond == null) throw new NullPointerException("The outputstream must not be null."); if (conProp == null) throw new NullPointerException("The connection property structure must not be null."); @@ -1282,6 +1293,18 @@ public final class httpd implements serverHandler { headerStringBuffer.append(httpVersion).append(" ") .append(Integer.toString(httpStatusCode)).append(" ") .append(httpStatusText).append("\r\n"); + //read custom headers + if (requestProperties != null) + { + Iterator it=requestProperties.getRequestProperties(); + while(it.hasNext()) + { + //Append user properties to the main String + //TODO: Should we check for user properites. What if they intersect properties that are already in header? + java.util.Map.Entry e=(java.util.Map.Entry)it.next(); + headerStringBuffer.append(e.getKey()).append(": ").append(e.getValue()).append("\r\n"); + } + } // write header Iterator i = header.keySet().iterator(); diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index b7d7d18cf..49b5f6905 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -447,6 +447,8 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http } //File targetClass = rewriteClassFile(targetFile); + //We need tp here + serverObjects tp = new serverObjects(); Date targetDate; boolean nocache = false; @@ -527,7 +529,7 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http // call rewrite-class - serverObjects tp = new serverObjects(); + if (targetClass == null) { targetDate = new Date(targetFile.lastModified()); } else { @@ -669,7 +671,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, nocache); + httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, result.length, targetDate, null, tp, (zipContent)?"gzip":null, null, nocache); if (! method.equals(httpHeader.METHOD_HEAD)) { Thread.sleep(200); // this solved the message problem (!!) serverFileUtils.write(result, out); diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java index c422dcd61..c40b00e45 100644 --- a/source/de/anomic/server/serverObjects.java +++ b/source/de/anomic/server/serverObjects.java @@ -61,10 +61,13 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.sql.Date; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; import java.util.Map; +import java.util.Vector; public final class serverObjects extends Hashtable implements Cloneable { @@ -208,4 +211,158 @@ public final class serverObjects extends Hashtable implements Cloneable { return super.clone(); } + /* + * Patch BEGIN: + * Name: Header Property Patch + * Date: Fri. 13.01.2006 + * Description: Makes possible to send header properties such as coockies back to the client. + * Part 1 of 5 + * Questions: sergej.z@list.ru + */ + /** + * Holds header properties + */ + //Since properties such as coockies can be multiple, we cannot use HashMap here. We have to use Vector. + private Vector requestProperty=new Vector(); + /** + * + * Implementation of Map.Entry. Structure that hold two values - exactly what we need! + */ + class Entry implements Map.Entry + { + private Object Key; + private Object Value; + Entry(Object Key,String Value){this.Key=Key;this.Value=Value;} + public Object getKey() {return Key;} + public Object getValue() {return Value;} + public Object setValue(Object Value) {return(this.Value=Value);} + } + /** + * Set a header property name with value + * @param name : name of the property. Ex. Location + * @param value : value of the property + * + * We can achieve redirection using property Location + * setRequestProperty("Location", "http://www.yacy.net"); + * Coockies can be convinently defined with setCookie method + */ + public void setRequestProperty(String name, String value) + { + /* + * TODO: Maybe we should check here if the property name is in RFC2616 + * And check for the validity of the value as well... + * */ + requestProperty.add(new Entry(name,value)); + + } + /** + * Sets Cookie on the client machine. + * + * @param name: Coockie name + * @param value: Coockie value + * @param expires: when should this coockie be autmatically deleted. If null - coockie will stay forever + * @param path: Path the coockie belongs to. Default - "/". Can be null. + * @param domain: Domain this cookie belongs to. Default - domain name. Can be null. + * @param secure: If true coockie will be send only over safe connection such as https + * Further documentation at docs.sun.com + */ + public void setCoockie(String name, String value, String expires, String path, String domain, boolean secure) + { + /* + * TODO:Here every value can be validated for correctness if needed + * For example semicolon should be not in any of the values + * However an exception in this case would be an overhead IMHO. + */ + String coockieString=name+"="+value+";"; + if(expires!=null) + coockieString+=" expires="+expires+";"; + if(path!=null) + coockieString+=" path="+path+";"; + if(domain!=null) + coockieString+=" domain="+domain+";"; + if(secure) + coockieString+=" secure;"; + requestProperty.add(new Entry("Set-Cookie",coockieString)); + } + /** + * Sets Cookie on the client machine. + * + * @param name: Coockie name + * @param value: Coockie value + * @param expires: when should this coockie be autmatically deleted. If null - coockie will stay forever + * @param path: Path the coockie belongs to. Default - "/". Can be null. + * @param domain: Domain this cookie belongs to. Default - domain name. Can be null. + * + * Note: this coockie will be sent over each connection independend if it is safe connection or not. + * Further documentation at docs.sun.com + */ + public void setCoockie(String name, String value, String expires, String path, String domain) + { + setCoockie( name, value, expires, path, domain, false); + } + /** + * Sets Cookie on the client machine. + * + * @param name: Coockie name + * @param value: Coockie value + * @param expires: when should this coockie be autmatically deleted. If null - coockie will stay forever + * @param path: Path the coockie belongs to. Default - "/". Can be null. + * + * Note: this coockie will be sent over each connection independend if it is safe connection or not. + * Further documentation at docs.sun.com + */ + public void setCoockie(String name, String value, String expires, String path) + { + setCoockie( name, value, expires, path, null, false); + } + /** + * Sets Cookie on the client machine. + * + * @param name: Coockie name + * @param value: Coockie value + * @param expires: when should this coockie be autmatically deleted. If null - coockie will stay forever + * + * Note: this coockie will be sent over each connection independend if it is safe connection or not. + * Further documentation at docs.sun.com + */ + public void setCoockie(String name, String value, String expires) + { + setCoockie( name, value, expires, null, null, false); + } + /** + * Sets Cookie on the client machine. + * + * @param name: Coockie name + * @param value: Coockie value + * + * Note: this coockie will be sent over each connection independend if it is safe connection or not. This coockie never expires + * Further documentation at docs.sun.com + */ + public void setCoockie(String name, String value ) + { + setCoockie( name, value, null, null, null, false); + } + /** + * Returns an iterator within all properties can be reached. + * Is used mainly by httpd. + * @return iterator to read all request properties. + * + * Example: + * + * Iterator it=serverObjects.getRequestProperties(); + * while(it.hasNext()) + * { + * java.util.Map.Entry e=(java.util.Map.Entry)it.next(); + * String propertyName=e.getKey(); + * String propertyValue=e.getValue(); + * } + */ + public Iterator getRequestProperties() + { + return requestProperty.iterator(); + } + /* + * Patch END: + * Name: Header Property Patch + */ } \ No newline at end of file