diff --git a/VERSION.txt b/VERSION.txt index 01a7a2ee247..1f1758d835e 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 949cc2fb4f5..5ef0bb7a69e 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 146db9d433c..9905a1f9fb5 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)