Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-04-12 10:24:50 +0000
committerGreg Wilkins2012-04-12 10:24:50 +0000
commitf9a75984f05d8cce6e15b452b322eaa96729c03c (patch)
treeedf01545b0badbbcc213b2296689dd6e343f344f /jetty-http/src
parent4089f3af779e70c87191394a6d6e2cf50bcbfd2b (diff)
downloadorg.eclipse.jetty.project-f9a75984f05d8cce6e15b452b322eaa96729c03c.tar.gz
org.eclipse.jetty.project-f9a75984f05d8cce6e15b452b322eaa96729c03c.tar.xz
org.eclipse.jetty.project-f9a75984f05d8cce6e15b452b322eaa96729c03c.zip
374504: updated cookies for rfc6265
Diffstat (limited to 'jetty-http/src')
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java55
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java24
2 files changed, 18 insertions, 61 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
index ed2989b7ff..aed0c3945d 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
@@ -293,7 +293,6 @@ public class HttpFields
/* -------------------------------------------------------------- */
private final ArrayList<Field> _fields = new ArrayList<Field>(20);
private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32);
- private final int _maxCookieVersion;
/* ------------------------------------------------------------ */
/**
@@ -301,19 +300,8 @@ public class HttpFields
*/
public HttpFields()
{
- _maxCookieVersion=1;
}
- /* ------------------------------------------------------------ */
- /**
- * Constructor.
- */
- public HttpFields(int maxCookieVersion)
- {
- _maxCookieVersion=maxCookieVersion;
- }
-
-
// TODO externalize this cache so it can be configurable
private static ConcurrentMap<String, Buffer> __cache = new ConcurrentHashMap<String, Buffer>();
private static int __cacheSize = Integer.getInteger("org.eclipse.jetty.http.HttpFields.CACHE",2000);
@@ -929,7 +917,7 @@ public class HttpFields
final boolean isHttpOnly,
int version)
{
- String delim=_maxCookieVersion==0?"":__COOKIE_DELIM;
+ String delim=__COOKIE_DELIM;
// Check arguments
if (name == null || name.length() == 0)
@@ -938,29 +926,18 @@ public class HttpFields
// Format value and params
StringBuilder buf = new StringBuilder(128);
String name_value_params;
- boolean quoted = QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
+ QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
buf.append('=');
String start=buf.toString();
if (value != null && value.length() > 0)
- quoted|=QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
-
- // upgrade to version 1 cookies if quoted.
- if (quoted&&version==0 && _maxCookieVersion>=1)
- version=1;
+ QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
- if (version>_maxCookieVersion)
- version=_maxCookieVersion;
-
- if (version > 0)
+ if (comment != null && comment.length() > 0)
{
- buf.append(";Version=");
- buf.append(version);
- if (comment != null && comment.length() > 0)
- {
- buf.append(";Comment=");
- QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
- }
+ buf.append(";Comment=");
+ QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
}
+
if (path != null && path.length() > 0)
{
buf.append(";Path=");
@@ -977,23 +954,19 @@ public class HttpFields
if (maxAge >= 0)
{
- // Always add the expires param as some browsers still don't handle max-age
- buf.append(";Expires=");
- if (maxAge == 0)
- buf.append(__01Jan1970_COOKIE);
- else
- formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
-
+ // Always add the expires param as some browsers still don't handle max-age
+ buf.append(";Expires=");
+ if (maxAge == 0)
+ buf.append(__01Jan1970_COOKIE);
+ else
+ formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
+
if (version >0)
{
buf.append(";Max-Age=");
buf.append(maxAge);
}
}
- else if (version > 0)
- {
- buf.append(";Discard");
- }
if (isSecure)
buf.append(";Secure");
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
index 3ae9a409fd..4d36e9aa3b 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
@@ -361,28 +361,18 @@ public class HttpFieldsTest
fields.clear();
fields.addSetCookie("everything","wrong","wrong","wrong",0,"to be replaced",true,true,0);
fields.addSetCookie("everything","value","domain","path",0,"comment",true,true,0);
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
+ assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
Enumeration<String> e =fields.getValues("Set-Cookie");
assertTrue(e.hasMoreElements());
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
+ assertEquals("everything=value;Comment=comment;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
assertFalse(e.hasMoreElements());
- assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
-
+ assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
fields.clear();
fields.addSetCookie("ev erything","va lue","do main","pa th",1,"co mment",true,true,2);
String setCookie=fields.getStringField("Set-Cookie");
- assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Version=1;Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
+ assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
assertTrue(setCookie.endsWith("GMT;Max-Age=1;Secure;HttpOnly"));
-
- fields.clear();
- fields.addSetCookie("name","value",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals(-1,setCookie.indexOf("Version="));
- fields.clear();
- fields.addSetCookie("name","v a l u e",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals(17,setCookie.indexOf("Version=1"));
fields.clear();
fields.addSetCookie("json","{\"services\":[\"cwa\", \"aa\"]}",null,null,-1,null,false,false,-1);
@@ -401,12 +391,6 @@ public class HttpFieldsTest
e=fields.getValues("Set-Cookie");
assertEquals("name=more;Domain=domain",e.nextElement());
assertEquals("foo=bob;Domain=domain",e.nextElement());
-
- fields=new HttpFields(0);
- fields.addSetCookie("name","value==",null,null,-1,null,false,false,0);
- setCookie=fields.getStringField("Set-Cookie");
- assertEquals("name=value==",setCookie);
-
}
private Set<String> enum2set(Enumeration<String> e)

Back to the top