Patch for the Coockie management.

Version 0.1

Start Yacy, go to localhost:8080/CookieTest.html
Play around with cookies
Look into CookieTest.java to See, how it works

This behavior will be changed 
such that httpHeader will be responsible for the cookies in the future



git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1332 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
(no author) 19 years ago
parent 239a904888
commit 55f3232219

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="source"/>
<classpathentry excluding="env/|htdocsdefault/|proxymsg/|yacy/" kind="src" path="htroot"/>
<classpathentry kind="src" path="htroot/htdocsdefault"/>
<classpathentry kind="src" path="htroot/yacy"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/commons-collections.jar"/>
<classpathentry kind="lib" path="lib/commons-pool-1.2.jar"/>
<classpathentry kind="lib" path="libx/axis.jar"/>
<classpathentry kind="lib" path="libx/axis-ant.jar"/>
<classpathentry kind="lib" path="libx/bzip2.jar"/>
<classpathentry kind="lib" path="libx/commons-discovery.jar"/>
<classpathentry kind="lib" path="libx/commons-logging.jar"/>
<classpathentry kind="lib" path="libx/informa-0.6.0.jar"/>
<classpathentry kind="lib" path="libx/jakarta-oro-2.0.7.jar"/>
<classpathentry kind="lib" path="libx/jaxrpc.jar"/>
<classpathentry kind="lib" path="libx/jdom.jar"/>
<classpathentry kind="lib" path="libx/jmimemagic-0.0.4a.jar"/>
<classpathentry kind="lib" path="libx/jsch-0.1.21.jar"/>
<classpathentry kind="lib" path="libx/log4j-1.2.9.jar"/>
<classpathentry kind="lib" path="libx/PDFBox-0.7.2.jar"/>
<classpathentry kind="lib" path="libx/saaj.jar"/>
<classpathentry kind="lib" path="libx/tar.jar"/>
<classpathentry kind="lib" path="libx/tm-extractors-0.4.jar"/>
<classpathentry kind="lib" path="libx/wsdl4j.jar"/>
<classpathentry kind="lib" path="libx/xerces.jar"/>
<classpathentry kind="lib" path="libx/odf_utils_05_11_10.jar"/>
<classpathentry kind="lib" path="libx/jrpm-head.jar"/>
<classpathentry kind="lib" path="libx/jrpm-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libx/commons-codec-1.3.jar"/>
<classpathentry kind="output" path="gen"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="source"/>
<classpathentry excluding="env/|htdocsdefault/|proxymsg/|yacy/" output="htroot" kind="src" path="htroot"/>
<classpathentry kind="src" path="htroot/htdocsdefault"/>
<classpathentry kind="src" path="htroot/yacy"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/commons-collections.jar"/>
<classpathentry kind="lib" path="lib/commons-pool-1.2.jar"/>
<classpathentry kind="lib" path="libx/axis.jar"/>
<classpathentry kind="lib" path="libx/axis-ant.jar"/>
<classpathentry kind="lib" path="libx/bzip2.jar"/>
<classpathentry kind="lib" path="libx/commons-discovery.jar"/>
<classpathentry kind="lib" path="libx/commons-logging.jar"/>
<classpathentry kind="lib" path="libx/informa-0.6.0.jar"/>
<classpathentry kind="lib" path="libx/jakarta-oro-2.0.7.jar"/>
<classpathentry kind="lib" path="libx/jaxrpc.jar"/>
<classpathentry kind="lib" path="libx/jdom.jar"/>
<classpathentry kind="lib" path="libx/jmimemagic-0.0.4a.jar"/>
<classpathentry kind="lib" path="libx/jsch-0.1.21.jar"/>
<classpathentry kind="lib" path="libx/log4j-1.2.9.jar"/>
<classpathentry kind="lib" path="libx/PDFBox-0.7.2.jar"/>
<classpathentry kind="lib" path="libx/saaj.jar"/>
<classpathentry kind="lib" path="libx/tar.jar"/>
<classpathentry kind="lib" path="libx/tm-extractors-0.4.jar"/>
<classpathentry kind="lib" path="libx/wsdl4j.jar"/>
<classpathentry kind="lib" path="libx/xerces.jar"/>
<classpathentry kind="lib" path="libx/odf_utils_05_11_10.jar"/>
<classpathentry kind="lib" path="libx/jrpm-head.jar"/>
<classpathentry kind="lib" path="libx/jrpm-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libx/commons-codec-1.3.jar"/>
<classpathentry kind="output" path="gen"/>
</classpath>

@ -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();

@ -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);

@ -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 <b>name</b> with <b>value</b>
* @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 <b>null</b> - coockie will stay forever
* @param path: Path the coockie belongs to. Default - "/". Can be <b>null</b>.
* @param domain: Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
* @param secure: If true coockie will be send only over safe connection such as https
* Further documentation at <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
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 <b>null</b> - coockie will stay forever
* @param path: Path the coockie belongs to. Default - "/". Can be <b>null</b>.
* @param domain: Domain this cookie belongs to. Default - domain name. Can be <b>null</b>.
*
* Note: this coockie will be sent over each connection independend if it is safe connection or not.
* Further documentation at <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
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 <b>null</b> - coockie will stay forever
* @param path: Path the coockie belongs to. Default - "/". Can be <b>null</b>.
*
* Note: this coockie will be sent over each connection independend if it is safe connection or not.
* Further documentation at <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
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 <b>null</b> - coockie will stay forever
*
* Note: this coockie will be sent over each connection independend if it is safe connection or not.
* Further documentation at <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
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 <a href="http://docs.sun.com/source/816-6408-10/cookies.htm">docs.sun.com</a>
*/
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
*/
}
Loading…
Cancel
Save