diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index e8ec2632b..1e71267a2 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -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 + * Partial NTLM support (requires an external NTLM engine). For details see NTLM_SUPPORT.txt Contributed by Oleg Kalnichevski diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java index b39becfea..156a6014e 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/BestMatchSpec.java @@ -83,7 +83,11 @@ public class BestMatchSpec implements CookieSpec { 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; } diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java index 96793bbe6..ae2db20f3 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java @@ -59,7 +59,7 @@ import org.apache.http.util.CharArrayBuffer; 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, diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java index 391b869f5..ee6b7beae 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java @@ -64,18 +64,32 @@ import org.apache.http.util.CharArrayBuffer; */ 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 Cookies. * diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java index 8898956d7..c20bd847d 100644 --- a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java +++ b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpecFactory.java @@ -33,6 +33,7 @@ package org.apache.http.impl.cookie; 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 @@ import org.apache.http.params.HttpParams; 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(); + } } }