Author: markt Date: Thu Oct 2 07:13:10 2014 New Revision: 1628896 URL: http://svn.apache.org/r1628896 Log: Add Max-Age support to the RFC 6265 cookie processor
Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java tomcat/trunk/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java?rev=1628896&r1=1628895&r2=1628896&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java Thu Oct 2 07:13:10 2014 @@ -87,7 +87,15 @@ public class Rfc6265CookieProcessor impl header.append(value); } - // TODO add support for the attributes. + // RFC 6265 prefers Max-Age to Expires so use Max-Age + int maxAge = cookie.getMaxAge(); + if (maxAge > -1) { + // Negative Max-Age is equivalent to no Max-Age + header.append(";Max-Age="); + header.append(maxAge); + } + + // TODO add support for the remaining attributes. return header.toString(); } Modified: tomcat/trunk/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java?rev=1628896&r1=1628895&r2=1628896&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java (original) +++ tomcat/trunk/test/org/apache/tomcat/util/http/TestCookieProcessorGeneration.java Thu Oct 2 07:13:10 2014 @@ -167,7 +167,6 @@ public class TestCookieProcessorGenerati doTestAllowSeparators(cookie, "foo=a\\b; Version=1", null); } - @Test public void v1ValueContainsBackslashAndQuote() { Cookie cookie = new Cookie("foo", "a\"b\\c"); @@ -176,6 +175,22 @@ public class TestCookieProcessorGenerati doTestAllowSeparators(cookie, "foo=a\"b\\c; Version=1", null); } + @Test + public void v1TestMaxAgePositive() { + doV1TestMaxAge(100, "foo=bar; Version=1; Max-Age=100", "foo=bar;Max-Age=100"); + } + + @Test + public void v1TestMaxAgeZero() { + doV1TestMaxAge(0, "foo=bar; Version=1; Max-Age=0", "foo=bar;Max-Age=0"); + } + + @Test + public void v1TestMaxAgeNegative() { + doV1TestMaxAge(-100, "foo=bar; Version=1", "foo=bar"); + } + + private void doTest(Cookie cookie, String expected) { doTest(cookie, expected, expected); } @@ -222,4 +237,14 @@ public class TestCookieProcessorGenerati Assert.assertEquals(expectedRfc6265, rfc6265.generateHeader(cookie)); } } + + + private void doV1TestMaxAge(int age, String expectedLegacy, String expectedRfc6265) { + LegacyCookieProcessor legacy = new LegacyCookieProcessor(); + legacy.setAlwaysAddExpires(false); + Cookie cookie = new Cookie("foo", "bar"); + cookie.setVersion(1); + cookie.setMaxAge(age); + doTest(cookie, legacy, expectedLegacy, new Rfc6265CookieProcessor(), expectedRfc6265); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org