hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1619780 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/cookie/ test/java/org/apache/http/impl/cookie/
Date Fri, 22 Aug 2014 12:35:14 GMT
Author: olegk
Date: Fri Aug 22 12:35:14 2014
New Revision: 1619780

URL: http://svn.apache.org/r1619780
Log:
BestMatchSpec to use Netscape policy instead of browser compatibility for netscape style cookies;
browser compatibility policy is to be deprecated

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieBestMatchSpec.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java?rev=1619780&r1=1619779&r2=1619780&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
Fri Aug 22 12:35:14 2014
@@ -58,7 +58,7 @@ public class BestMatchSpec implements Co
     // Cached values of CookieSpec instances
     private RFC2965Spec strict; // @NotThreadSafe
     private RFC2109Spec obsoleteStrict; // @NotThreadSafe
-    private BrowserCompatSpec compat; // @NotThreadSafe
+    private NetscapeDraftSpec netscape; // @NotThreadSafe
 
     public BestMatchSpec(final String[] datepatterns, final boolean oneHeader) {
         super();
@@ -84,11 +84,11 @@ public class BestMatchSpec implements Co
         return obsoleteStrict;
     }
 
-    private BrowserCompatSpec getCompat() {
-        if (this.compat == null) {
-            this.compat = new BrowserCompatSpec(this.datepatterns);
+    private NetscapeDraftSpec getNetscapeCompat() {
+        if (this.netscape == null) {
+            this.netscape = new NetscapeDraftSpec(false, this.datepatterns);
         }
-        return compat;
+        return netscape;
     }
 
     @Override
@@ -129,7 +129,7 @@ public class BestMatchSpec implements Co
                 cursor = new ParserCursor(0, buffer.length());
             }
             helems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
-            return getCompat().parse(helems, origin);
+            return getNetscapeCompat().parse(helems, origin);
         } else {
             if (SM.SET_COOKIE2.equals(header.getName())) {
                 return getStrict().parse(helems, origin);
@@ -152,7 +152,7 @@ public class BestMatchSpec implements Co
                 getObsoleteStrict().validate(cookie, origin);
             }
         } else {
-            getCompat().validate(cookie, origin);
+            getNetscapeCompat().validate(cookie, origin);
         }
     }
 
@@ -167,7 +167,7 @@ public class BestMatchSpec implements Co
                 return getObsoleteStrict().match(cookie, origin);
             }
         } else {
-            return getCompat().match(cookie, origin);
+            return getNetscapeCompat().match(cookie, origin);
         }
     }
 
@@ -191,7 +191,7 @@ public class BestMatchSpec implements Co
                 return getObsoleteStrict().formatCookies(cookies);
             }
         } else {
-            return getCompat().formatCookies(cookies);
+            return getNetscapeCompat().formatCookies(cookies);
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java?rev=1619780&r1=1619779&r2=1619780&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
Fri Aug 22 12:35:14 2014
@@ -59,8 +59,7 @@ public class NetscapeDraftSpec extends C
 
     private final String[] datepatterns;
 
-    /** Default constructor */
-    public NetscapeDraftSpec(final String[] datepatterns) {
+    NetscapeDraftSpec(final boolean strictDomainValidation, final String[] datepatterns)
{
         super();
         if (datepatterns != null) {
             this.datepatterns = datepatterns.clone();
@@ -68,14 +67,18 @@ public class NetscapeDraftSpec extends C
             this.datepatterns = new String[] { EXPIRES_PATTERN };
         }
         registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler());
-        registerAttribHandler(ClientCookie.DOMAIN_ATTR, new NetscapeDomainHandler());
+        registerAttribHandler(ClientCookie.DOMAIN_ATTR,
+                strictDomainValidation ? new NetscapeDomainHandler() : new BasicDomainHandler());
         registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler());
         registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler());
         registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(
                 this.datepatterns));
     }
 
-    /** Default constructor */
+    public NetscapeDraftSpec(final String[] datepatterns) {
+        this(true, datepatterns);
+    }
+
     public NetscapeDraftSpec() {
         this(null);
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieBestMatchSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieBestMatchSpec.java?rev=1619780&r1=1619779&r2=1619780&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieBestMatchSpec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestCookieBestMatchSpec.java
Fri Aug 22 12:35:14 2014
@@ -277,5 +277,23 @@ public class TestCookieBestMatchSpec {
         }
     }
 
+    @Test
+    public void testVersion1CookieWithInvalidExpires() throws Exception {
+        final CookieSpec cookiespec = new BestMatchSpec();
+        final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
+
+        final Header origHeader = new BasicHeader("Set-Cookie",
+                "test=\"test\"; Version=1; Expires=Mon, 11-Feb-2013 10:39:19 GMT; Path=/");
+        final List<Cookie> cookies = cookiespec.parse(origHeader, origin);
+        Assert.assertNotNull(cookies);
+        Assert.assertEquals(1, cookies.size());
+
+        final List<Header> headers = cookiespec.formatCookies(cookies);
+        Assert.assertNotNull(headers);
+        Assert.assertEquals(1, headers.size());
+        final Header header1 = headers.get(0);
+        Assert.assertEquals("test=\"test\"", header1.getValue());
+    }
+
 }
 



Mime
View raw message