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 ed2989b7ff5..aed0c3945d3 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 _fields = new ArrayList(20); private final HashMap _names = new HashMap(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 __cache = new ConcurrentHashMap(); 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 3ae9a409fd0..4d36e9aa3b7 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 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 enum2set(Enumeration e) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java index a30c70f78cc..2a5ba0d8f0f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java @@ -146,7 +146,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection HttpBuffers ab = (HttpBuffers)_connector; _parser = newHttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler()); _requestFields = new HttpFields(); - _responseFields = new HttpFields(server.getMaxCookieVersion()); + _responseFields = new HttpFields(); _request = new Request(this); _response = new Response(this); _generator = newHttpGenerator(ab.getResponseBuffers(), endpoint); @@ -164,7 +164,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection _connector = connector; _parser = parser; _requestFields = new HttpFields(); - _responseFields = new HttpFields(server.getMaxCookieVersion()); + _responseFields = new HttpFields(); _request = request; _response = new Response(this); _generator = generator; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 9189dbb8e9b..e362aaaafde 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -136,7 +136,7 @@ public class Response implements HttpServletResponse if (i>=0) { http_only=true; - comment=comment.substring(i,i+HTTP_ONLY_COMMENT.length()).trim(); + comment=comment.replace(HTTP_ONLY_COMMENT,"").trim(); if (comment.length()==0) comment=null; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 9a01f509562..32850f47a5d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -72,7 +72,6 @@ public class Server extends HandlerWrapper implements Attributes private boolean _sendDateHeader = false; //send Date: header private int _graceful=0; private boolean _stopAtShutdown; - private int _maxCookieVersion=1; private boolean _dumpAfterStart=false; private boolean _dumpBeforeStop=false; private boolean _uncheckedPrintWriter=false; @@ -450,21 +449,20 @@ public class Server extends HandlerWrapper implements Attributes } /* ------------------------------------------------------------ */ - /** Get the maximum cookie version. - * @return the maximum set-cookie version sent by this server + /** */ + @Deprecated public int getMaxCookieVersion() { - return _maxCookieVersion; + return 1; } /* ------------------------------------------------------------ */ - /** Set the maximum cookie version. - * @param maxCookieVersion the maximum set-cookie version sent by this server + /** */ + @Deprecated public void setMaxCookieVersion(int maxCookieVersion) { - _maxCookieVersion = maxCookieVersion; } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index b936a5f6513..a3af0709931 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -516,7 +516,7 @@ public class ResponseTest String set = response.getHttpFields().getStringField("Set-Cookie"); - assertEquals("name=value;Path=/path;Domain=domain;Secure;HttpOnly",set); + assertEquals("name=value;Comment=comment;Path=/path;Domain=domain;Secure;HttpOnly",set); } private Response newResponse()