hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r531455 - in /jakarta/httpcomponents/httpclient/trunk/src: java/org/apache/http/client/ java/org/apache/http/cookie/ java/org/apache/http/impl/cookie/ test/org/apache/http/impl/cookie/
Date Mon, 23 Apr 2007 12:54:54 GMT
Author: olegk
Date: Mon Apr 23 05:54:52 2007
New Revision: 531455

URL: http://svn.apache.org/viewvc?view=rev&rev=531455
Log:
Changed Cookie#isExpired() to take current system time as an argument instead of obtaining
it through System#currentTimeMillis()

Suggested by Roland Weber

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpState.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/cookie/BasicExpiresHandler.java
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/cookie/TestBasicCookieAttribHandlers.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpState.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpState.java?view=diff&rev=531455&r1=531454&r2=531455
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpState.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpState.java
Mon Apr 23 05:54:52 2007
@@ -31,6 +31,7 @@
 package org.apache.http.client;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 
@@ -109,7 +110,7 @@
                     break;
                 }
             }
-            if (!cookie.isExpired()) {
+            if (!cookie.isExpired(new Date())) {
                 cookies.add(cookie);
             }
         }
@@ -155,9 +156,10 @@
      */
     public synchronized boolean purgeExpiredCookies() {
         boolean removed = false;
+        Date now = new Date();
         Iterator it = cookies.iterator();
         while (it.hasNext()) {
-            if (((Cookie) (it.next())).isExpired()) {
+            if (((Cookie) (it.next())).isExpired(now)) {
                 it.remove();
                 removed = true;
             }

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java?view=diff&rev=531455&r1=531454&r2=531455
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/cookie/Cookie.java Mon
Apr 23 05:54:52 2007
@@ -256,12 +256,16 @@
 
     /**
      * Returns true if this cookie has expired.
+     * @param date Current time
      * 
      * @return <tt>true</tt> if the cookie has expired.
      */
-    public boolean isExpired() {
+    public boolean isExpired(final Date date) {
+        if (date == null) {
+            throw new IllegalArgumentException("Date may not be null");
+        }
         return (cookieExpiryDate != null  
-            && cookieExpiryDate.getTime() <= System.currentTimeMillis());
+            && cookieExpiryDate.getTime() <= date.getTime());
     }
 
     /**

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/cookie/BasicExpiresHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/cookie/BasicExpiresHandler.java?view=diff&rev=531455&r1=531454&r2=531455
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/cookie/BasicExpiresHandler.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/cookie/BasicExpiresHandler.java
Mon Apr 23 05:54:52 2007
@@ -31,7 +31,6 @@
 package org.apache.http.impl.cookie;
 
 import org.apache.http.cookie.Cookie;
-import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.MalformedCookieException;
 import org.apache.http.util.DateParseException;
 import org.apache.http.util.DateUtils;
@@ -64,11 +63,4 @@
         }
     }
 
-    public boolean match(final Cookie cookie, final CookieOrigin origin) {
-        if (cookie == null) {
-            throw new IllegalArgumentException("Cookie may not be null");
-        }
-        return !cookie.isExpired();
-    }
-    
 }

Modified: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/cookie/TestBasicCookieAttribHandlers.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/cookie/TestBasicCookieAttribHandlers.java?view=diff&rev=531455&r1=531454&r2=531455
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/cookie/TestBasicCookieAttribHandlers.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/impl/cookie/TestBasicCookieAttribHandlers.java
Mon Apr 23 05:54:52 2007
@@ -447,20 +447,6 @@
         }
     }
 
-    public void testBasicExpiresMatch() throws Exception {
-        Cookie cookie = new Cookie("name", "value"); 
-        CookieAttributeHandler h = new BasicExpiresHandler(new String[] {DateUtils.PATTERN_RFC1123});
-        CookieOrigin origin = new CookieOrigin("somehost", 80, "/stuff", false); 
-        
-        Date past = new Date(System.currentTimeMillis() - 20000000);
-        Date future = new Date(System.currentTimeMillis() + 20000000);
-        
-        cookie.setExpiryDate(past);
-        assertFalse(h.match(cookie, origin));
-        cookie.setExpiryDate(future);
-        assertTrue(h.match(cookie, origin));
-    }
-    
     public void testBasicExpiresInvalidInput() throws Exception {
         try {
             new BasicExpiresHandler(null);
@@ -471,12 +457,6 @@
         CookieAttributeHandler h = new BasicExpiresHandler(new String[] {DateUtils.PATTERN_RFC1123});
         try {
             h.parse(null, null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            h.match(null, null);
             fail("IllegalArgumentException must have been thrown");
         } catch (IllegalArgumentException ex) {
             // expected



Mime
View raw message