diff --git a/htroot/CookieTest.html b/htroot/CookieTest.html
index dd417e5af..479048f22 100644
--- a/htroot/CookieTest.html
+++ b/htroot/CookieTest.html
@@ -10,6 +10,12 @@
Here is a cookie test page.
+
+
+
@@ -26,24 +32,28 @@ Cookies at this browser:
+
+
+
+#(cookiesout)#
+::
+Cookies coming to server:
+#(/cookiesout)#
+#{cookiesout}#
+#[string]#
+#{/cookiesout}#
+
#(cookiesin)#
-Cookies coming to server:
::
+
+
+Cookies server sent:
#(/cookiesin)#
#{cookiesin}#
#[name]# = #[value]#
#{/cookiesin}#
-
-
-#(cookiesout)#
-Cookies server sent:
-::
-#(/cookiesout)#
-#{cookiesout}#
-#[name]# = #[value]#
-#{/cookiesout}#
diff --git a/htroot/CookieTest.java b/htroot/CookieTest.java
index 8149cc0b1..d92e5eb7b 100644
--- a/htroot/CookieTest.java
+++ b/htroot/CookieTest.java
@@ -82,21 +82,26 @@ public class CookieTest {
final serverObjects prop = new serverObjects();
if(post.containsKey("act")&&post.get("act").equals("clear_cookie"))
{
-
+ httpHeader outgoingHeader=new httpHeader();
Iterator it = header.entrySet().iterator();
while(it.hasNext())
{
java.util.Map.Entry e = (Entry) it.next();
- if(e.getKey().equals("Cookie"));
- prop.setCoockie(
- (String)e.getKey(),
- (String)e.getValue(),
- "expires=Thu, 01-Jan-99 00:00:01 GMT"
- );
+ if(e.getKey().equals("Cookie"))
+ {
+ String coockie[]=e.getValue().toString().split(";");
+ for(int i=0;i1?(nameValue[1].trim()):"","Thu, 01-Jan-99 00:00:01 GMT");
+ }
+ }
+
+
}
-
+ prop.setOutgoingHeader(outgoingHeader);
prop.put("coockiesout",0);
//header.
@@ -105,18 +110,29 @@ public class CookieTest {
{
String CoockieName = post.get("cookie_name").toString().trim();
String CoockieValue = post.get("cookie_value").toString().trim();
- prop.setCoockie(CoockieName,CoockieValue);
- prop.put("cookiesout",1);
- prop.put("cookiesout_0_name",CoockieName);
- prop.put("cookiesout_0_value",CoockieValue);
+ httpHeader outgoingHeader=new httpHeader();
+
+ outgoingHeader.setCoockie(CoockieName,CoockieValue);
+ prop.setOutgoingHeader(outgoingHeader);
+ prop.put("cookiesin",1);
+ prop.put("cookiesin_0_name",CoockieName);
+ prop.put("cookiesin_0_value",CoockieValue);
//header.
}
Iterator it = header.entrySet().iterator();
+
while(it.hasNext())
{
java.util.Map.Entry e = (Entry) it.next();
System.out.println(""+e.getKey()+" : "+e.getValue());
+ if(e.getKey().equals("Cookie"))
+ {
+ String a;
+
+ prop.put("cookiesout",1);
+ prop.put("cookiesout_0_string",e.getValue().toString().replaceAll(";",";
"));
+ }
}
return prop;
diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.java
index aa7fc7c30..f5166a4ce 100644
--- a/source/de/anomic/http/httpHeader.java
+++ b/source/de/anomic/http/httpHeader.java
@@ -70,10 +70,12 @@ import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
+import java.util.Vector;
import de.anomic.server.serverCore;
import de.anomic.server.logging.serverLog;
+
public final class httpHeader extends TreeMap implements Map {
@@ -718,4 +720,141 @@ public final class httpHeader extends TreeMap implements Map {
String dstHostSocket = (String) header.get(httpHeader.HOST);
prop.setProperty(CONNECTION_PROP_HOST,(httpd.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
}
+ /*
+ * 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 coockies=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);}
+ }
+
+ /**
+ * 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;";
+ coockies.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 getCookies()
+ {
+ return coockies.iterator();
+ }
+ /*
+ * Patch END:
+ * Name: Header Property Patch
+ */
}
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index bb8d3255b..08031b3cb 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,
- serverObjects requestProperties,
+ httpHeader headers,
String contentEnc,
String transferEnc
) throws IOException {
- sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,contentType,contentLength,moddate,expires,requestProperties,contentEnc,transferEnc,true);
+ sendRespondHeader(conProp,respond,httpVersion,httpStatusCode,httpStatusText,contentType,contentLength,moddate,expires,headers,contentEnc,transferEnc,true);
}
public static final void sendRespondHeader(
@@ -1191,13 +1191,13 @@ public final class httpd implements serverHandler {
long contentLength,
Date moddate,
Date expires,
- serverObjects requestProperties,
+ httpHeader headers,
String contentEnc,
String transferEnc,
boolean nocache
) throws IOException {
- httpHeader headers = new httpHeader();
+ if(headers==null)headers = new httpHeader();
Date now = new Date(System.currentTimeMillis());
headers.put(httpHeader.SERVER, "AnomicHTTPD (www.anomic.de)");
@@ -1216,7 +1216,7 @@ public final class httpd implements serverHandler {
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,requestProperties);
+ sendRespondHeader(conProp, respond, httpVersion, httpStatusCode, httpStatusText, headers);
}
public static final void sendRespondHeader(
@@ -1228,25 +1228,14 @@ 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,
- 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
+ httpHeader header
) throws IOException {
if (respond == null) throw new NullPointerException("The outputstream must not be null.");
@@ -1294,9 +1283,13 @@ public final class httpd implements serverHandler {
.append(Integer.toString(httpStatusCode)).append(" ")
.append(httpStatusText).append("\r\n");
//read custom headers
+ /*
if (requestProperties != null)
{
- Iterator it=requestProperties.getRequestProperties();
+ httpHeader outgoingHeader=requestProperties.getOutgoingHeader();
+ if (outgoingHeader!=null)
+ {*/
+ Iterator it=header.getCookies();
while(it.hasNext())
{
//Append user properties to the main String
@@ -1304,7 +1297,10 @@ public final class httpd implements serverHandler {
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 49b5f6905..a4c328c0a 100644
--- a/source/de/anomic/http/httpdFileHandler.java
+++ b/source/de/anomic/http/httpdFileHandler.java
@@ -671,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, tp, (zipContent)?"gzip":null, null, nocache);
+ httpd.sendRespondHeader(this.connectionProperties, out, httpVersion, 200, null, mimeType, result.length, targetDate, null, tp.getOutgoingHeader(), (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 c40b00e45..1ce462555 100644
--- a/source/de/anomic/server/serverObjects.java
+++ b/source/de/anomic/server/serverObjects.java
@@ -69,10 +69,22 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
+import de.anomic.http.httpHeader;
+
public final class serverObjects extends Hashtable implements Cloneable {
private static final long serialVersionUID = 1L;
-
+ private httpHeader outgoingHeader;
+ public void setOutgoingHeader(httpHeader outgoingHeader)
+ {
+ this.outgoingHeader=outgoingHeader;
+ }
+ public httpHeader getOutgoingHeader()
+ {
+ return outgoingHeader;
+ }
+
+
public serverObjects() {
super();
}
@@ -211,158 +223,4 @@ 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