hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r792645 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/src/main/java/org/apache/http/cookie/ httpclient/src/test/java/org/apache/http/impl/client/
Date Thu, 09 Jul 2009 19:29:12 GMT
Author: olegk
Date: Thu Jul  9 19:29:11 2009
New Revision: 792645

URL: http://svn.apache.org/viewvc?rev=792645&view=rev
Log:
HTTPCLIENT-859: CookieIdentityComparator now takes path attribute into consideration when
comparing cookies

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieIdentityComparator.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCookieIdentityComparator.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=792645&r1=792644&r2=792645&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Jul  9 19:29:11 2009
@@ -1,6 +1,10 @@
 Changes since 4.0 beta 2
 -------------------
 
+* [HTTPCLIENT-859] CookieIdentityComparator now takes path attribute into 
+  consideration when comparing cookies.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * HttpClient will no longer send expired cookies back to the origin server.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=792645&r1=792644&r2=792645&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Thu Jul  9 19:29:11 2009
@@ -176,7 +176,7 @@
         List<Cookie> matchedCookies = new ArrayList<Cookie>();
         Date now = new Date();
         for (Cookie cookie : cookies) {
-            if (cookie.getExpiryDate() == null || cookie.getExpiryDate().after(now)) {
+            if (!cookie.isExpired(now)) {
                 if (cookieSpec.match(cookie, cookieOrigin)) {
                     if (this.log.isDebugEnabled()) {
                         this.log.debug("Cookie " + cookie + " match " + cookieOrigin);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieIdentityComparator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieIdentityComparator.java?rev=792645&r1=792644&r2=792645&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieIdentityComparator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieIdentityComparator.java
Thu Jul  9 19:29:11 2009
@@ -67,6 +67,17 @@
             }
             res = d1.compareToIgnoreCase(d2);
         }
+        if (res == 0) {
+            String p1 = c1.getPath();
+            if (p1 == null) {
+                p1 = "/";
+            }
+            String p2 = c2.getPath();
+            if (p2 == null) {
+                p2 = "/";
+            }
+            res = p1.compareTo(p2);
+        }
         return res;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCookieIdentityComparator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCookieIdentityComparator.java?rev=792645&r1=792644&r2=792645&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCookieIdentityComparator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCookieIdentityComparator.java
Thu Jul  9 19:29:11 2009
@@ -116,4 +116,42 @@
         assertTrue(comparator.compare(c3, c4) == 0);
     }
 
+    public void testCookieIdentityComparasionByNameDomainAndPath() {
+        CookieIdentityComparator comparator = new CookieIdentityComparator(); 
+        BasicClientCookie c1 = new BasicClientCookie("name", "value1");
+        c1.setDomain("www.domain.com");
+        c1.setPath("/whatever");
+        BasicClientCookie c2 = new BasicClientCookie("name", "value2"); 
+        c2.setDomain("www.domain.com");
+        c2.setPath("/whatever");
+        assertTrue(comparator.compare(c1, c2) == 0);
+        
+        BasicClientCookie c3 = new BasicClientCookie("name", "value1"); 
+        c3.setDomain("www.domain.com");
+        c3.setPath("/whatever");
+        BasicClientCookie c4 = new BasicClientCookie("name", "value2"); 
+        c4.setDomain("domain.com");
+        c4.setPath("/whatever-not");
+        assertFalse(comparator.compare(c3, c4) == 0);
+    }
+
+    public void testCookieIdentityComparasionByNameDomainAndNullPath() {
+        CookieIdentityComparator comparator = new CookieIdentityComparator(); 
+        BasicClientCookie c1 = new BasicClientCookie("name", "value1");
+        c1.setDomain("www.domain.com");
+        c1.setPath("/");
+        BasicClientCookie c2 = new BasicClientCookie("name", "value2"); 
+        c2.setDomain("www.domain.com");
+        c2.setPath(null);
+        assertTrue(comparator.compare(c1, c2) == 0);
+        
+        BasicClientCookie c3 = new BasicClientCookie("name", "value1"); 
+        c3.setDomain("www.domain.com");
+        c3.setPath("/whatever");
+        BasicClientCookie c4 = new BasicClientCookie("name", "value2"); 
+        c4.setDomain("domain.com");
+        c4.setPath(null);
+        assertFalse(comparator.compare(c3, c4) == 0);
+    }
+
 }



Mime
View raw message