You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/05/17 13:44:16 UTC

svn commit: r657334 - in /httpcomponents/httpclient/trunk: ./ module-client/src/main/java/org/apache/http/impl/cookie/

Author: olegk
Date: Sat May 17 04:44:16 2008
New Revision: 657334

URL: http://svn.apache.org/viewvc?rev=657334&view=rev
Log:
HTTPCLIENT-773: Improved handling of the 'expires' attribute by the 'Best Match' cookie spec

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=657334&r1=657333&r2=657334&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Sat May 17 04:44:16 2008
@@ -1,6 +1,10 @@
 Changes since 4.0 Alpha 4
 -------------------
 
+* [HTTPCLIENT-773] Improved handling of the 'expires' attribute by the
+  'Best Match' cookie spec.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * Partial NTLM support (requires an external NTLM engine). For details see
   NTLM_SUPPORT.txt
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java?rev=657334&r1=657333&r2=657334&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java Sat May 17 04:44:16 2008
@@ -83,7 +83,11 @@
 
     private NetscapeDraftSpec getNetscape() {
         if (this.netscape == null) {
-            this.netscape = new NetscapeDraftSpec();
+            String[] patterns = this.datepatterns;
+            if (patterns == null) {
+                patterns = BrowserCompatSpec.DATE_PATTERNS;
+            }
+            this.netscape = new NetscapeDraftSpec(patterns);
         }
         return netscape;
     }

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java?rev=657334&r1=657333&r2=657334&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java Sat May 17 04:44:16 2008
@@ -59,7 +59,7 @@
 public class BrowserCompatSpec extends CookieSpecBase {
     
     /** Valid date patterns used per default */
-    private static final String[] DATE_PATTERNS = new String[] {
+    protected static final String[] DATE_PATTERNS = new String[] {
             DateUtils.PATTERN_RFC1123,
             DateUtils.PATTERN_RFC1036,
             DateUtils.PATTERN_ASCTIME,

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java?rev=657334&r1=657333&r2=657334&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java Sat May 17 04:44:16 2008
@@ -64,18 +64,32 @@
  */
 public class NetscapeDraftSpec extends CookieSpecBase {
 
+    protected static final String EXPIRES_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
+    
+    private final String[] datepatterns; 
+    
     /** Default constructor */
-    public NetscapeDraftSpec() {
+    public NetscapeDraftSpec(final String[] datepatterns) {
         super();
+        if (datepatterns != null) {
+            this.datepatterns = datepatterns.clone();
+        } else {
+            this.datepatterns = new String[] { EXPIRES_PATTERN };
+        }
         registerAttribHandler(ClientCookie.PATH_ATTR, new BasicPathHandler());
         registerAttribHandler(ClientCookie.DOMAIN_ATTR, new NetscapeDomainHandler());
         registerAttribHandler(ClientCookie.MAX_AGE_ATTR, new BasicMaxAgeHandler());
         registerAttribHandler(ClientCookie.SECURE_ATTR, new BasicSecureHandler());
         registerAttribHandler(ClientCookie.COMMENT_ATTR, new BasicCommentHandler());
         registerAttribHandler(ClientCookie.EXPIRES_ATTR, new BasicExpiresHandler(
-                new String[] {"EEE, dd-MMM-yyyy HH:mm:ss z"}));
+                this.datepatterns));
     }
 
+    /** Default constructor */
+    public NetscapeDraftSpec() {
+        this(null);
+    }
+    
     /**
       * Parses the Set-Cookie value into an array of <tt>Cookie</tt>s.
       *

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java?rev=657334&r1=657333&r2=657334&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java Sat May 17 04:44:16 2008
@@ -33,6 +33,7 @@
 
 import org.apache.http.cookie.CookieSpec;
 import org.apache.http.cookie.CookieSpecFactory;
+import org.apache.http.cookie.params.CookieSpecPNames;
 import org.apache.http.params.HttpParams;
 
 /**
@@ -44,7 +45,12 @@
 public class NetscapeDraftSpecFactory implements CookieSpecFactory {    
 
     public CookieSpec newInstance(final HttpParams params) {
-        return new NetscapeDraftSpec();
+        if (params != null) {
+            return new NetscapeDraftSpec(
+                    (String []) params.getParameter(CookieSpecPNames.DATE_PATTERNS));
+        } else {
+            return new NetscapeDraftSpec();
+        }
     }
 
 }