Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2010-05-03 23:28:25 +0000
committerGreg Wilkins2010-05-03 23:28:25 +0000
commit2f2c9cbe14e4282301d12ff17a725c9ffc906365 (patch)
treeac0db702479a0e7be7080c3ccc7c6177e358f6db
parentcc6b89040f75d89242c69b253253a30baa0d3f0b (diff)
downloadorg.eclipse.jetty.project-2f2c9cbe14e4282301d12ff17a725c9ffc906365.tar.gz
org.eclipse.jetty.project-2f2c9cbe14e4282301d12ff17a725c9ffc906365.tar.xz
org.eclipse.jetty.project-2f2c9cbe14e4282301d12ff17a725c9ffc906365.zip
JETTY-1142 Replace Set-Cookies with same name
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1683 7e9141cc-0065-0410-87d8-b60c137991c4
-rw-r--r--VERSION.txt1
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java19
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java15
3 files changed, 34 insertions, 1 deletions
diff --git a/VERSION.txt b/VERSION.txt
index 01a7a2ee24..1f1758d835 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -20,6 +20,7 @@ jetty-7.1.0.RC1-SNAPSHOT
+ 311362 Optional org.eclipse.jetty.util.log.stderr.SOURCE
+ 308864 Update test suite to JUnit4 - Module jetty-servlets
+ JETTY-1030 - Improve jetty.sh script
+ + JETTY-1142 Replace Set-Cookies with same name
jetty-7.1.0.RC0 27 April 2010
+ 294563 Websocket client connection
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 949cc2fb4f..5ef0bb7a69 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
@@ -983,6 +983,7 @@ public class HttpFields
String name_value_params;
QuotedStringTokenizer.quoteIfNeeded(buf, name);
buf.append('=');
+ String start=buf.toString();
if (value != null && value.length() > 0)
QuotedStringTokenizer.quoteIfNeeded(buf, value);
@@ -1039,6 +1040,24 @@ public class HttpFields
// TODO - straight to Buffer?
name_value_params = buf.toString();
put(HttpHeaders.EXPIRES_BUFFER, __01Jan1970_BUFFER);
+
+ // look for existing cookie
+ Field field = getField(HttpHeaders.SET_COOKIE_BUFFER);
+ if (field != null)
+ {
+ final int revision=_revision;
+
+ while (field!=null)
+ {
+ if (field._revision!=revision || field._value!=null && field._value.toString().startsWith(start))
+ {
+ field.reset(new ByteArrayBuffer(name_value_params),-1,revision);
+ return;
+ }
+ field=field._next;
+ }
+ }
+
add(HttpHeaders.SET_COOKIE_BUFFER, new ByteArrayBuffer(name_value_params));
}
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 146db9d433..9905a1f9fb 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
@@ -378,7 +378,20 @@ public class HttpFieldsTest extends TestCase
fields.clear();
fields.addSetCookie("json","{\"services\":[\"cwa\", \"aa\"]}",null,null,-1,null,false,false,-1);
assertEquals("json=\"{\\\"services\\\":[\\\"cwa\\\", \\\"aa\\\"]}\"",fields.getStringField("Set-Cookie"));
-
+
+ fields.clear();
+ fields.addSetCookie("name","value","domain",null,-1,null,false,false,-1);
+ fields.addSetCookie("name","other","domain",null,-1,null,false,false,-1);
+ assertEquals("name=other;Domain=domain",fields.getStringField("Set-Cookie"));
+ fields.addSetCookie("name","more","domain",null,-1,null,false,false,-1);
+ assertEquals("name=more;Domain=domain",fields.getStringField("Set-Cookie"));
+ fields.addSetCookie("foo","bar","domain",null,-1,null,false,false,-1);
+ fields.addSetCookie("foo","bob","domain",null,-1,null,false,false,-1);
+ assertEquals("name=more;Domain=domain",fields.getStringField("Set-Cookie"));
+
+ Enumeration e=fields.getValues("Set-Cookie");
+ assertEquals("name=more;Domain=domain",e.nextElement());
+ assertEquals("foo=bob;Domain=domain",e.nextElement());
}
private Set enum2set(Enumeration e)

Back to the top