HTTPCLIENT-773: Improved handling of the 'expires' attribute by the 'Best Match' cookie spec

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@657334 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-05-17 11:44:16 +00:00
parent 14d0e406a3
commit c9a4970c10
5 changed files with 33 additions and 5 deletions

View File

@ -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>

View File

@ -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;
}

View File

@ -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,

View File

@ -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 <tt>Cookie</tt>s.
*

View File

@ -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();
}
}
}