Deprecated browser compat policy in favor of the default (best match) policy

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1620940 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-08-27 17:07:53 +00:00
parent 139529327c
commit 45100c7d6d
8 changed files with 39 additions and 1089 deletions

View File

@ -56,6 +56,7 @@ import org.apache.http.util.CharArrayBuffer;
* common web browser applications such as Microsoft Internet Explorer
* and Mozilla FireFox.
*
* @deprecated (4.4) use {@link org.apache.http.impl.cookie.DefaultCookieSpec}.
*
* @since 4.0
*/

View File

@ -42,10 +42,12 @@ import org.apache.http.protocol.HttpContext;
* {@link org.apache.http.impl.cookie.BrowserCompatSpec}. The instance returned by this factory
* can be shared by multiple threads.
*
* @deprecated (4.4) use {@link org.apache.http.impl.cookie.DefaultCookieSpecProvider}.
*
* @since 4.0
*/
@Immutable
@SuppressWarnings("deprecation")
@Deprecated
public class BrowserCompatSpecFactory implements CookieSpecFactory, CookieSpecProvider {
public enum SecurityLevel {

View File

@ -37,6 +37,8 @@ import org.apache.http.util.Args;
/**
* {@code "Version"} cookie attribute handler for BrowserCompat cookie spec.
*
* @deprecated (4.4) no longer used.
*
* @since 4.3
*/
@Immutable

View File

@ -40,7 +40,10 @@ public final class CookieSpecs {
/**
* The policy that provides high degree of compatibility
* with common cookie management of popular HTTP agents.
*
* @deprecated (4.4) use {link #DEFAULT}.
*/
@Deprecated
public static final String BROWSER_COMPATIBILITY = "compatibility";
/**
@ -55,13 +58,16 @@ public final class CookieSpecs {
/**
* The default 'best match' policy.
* @deprecated (4.4) use {@link #DEFAULT}.
*
* @deprecated (4.4) use {link #DEFAULT}.
*/
@Deprecated
public static final String BEST_MATCH = "best-match";
/**
* The default policy.
* The default policy. This policy provides a higher degree of compatibility
* with common cookie management of popular HTTP agents for non-standard
* (Netscape style) cookies.
*/
public static final String DEFAULT = "default";

View File

@ -97,11 +97,9 @@ import org.apache.http.impl.conn.DefaultRoutePlanner;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
import org.apache.http.impl.cookie.IgnoreSpecFactory;
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2109SpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
import org.apache.http.impl.execchain.BackoffStrategyExec;
import org.apache.http.impl.execchain.ClientExecChain;
@ -1051,11 +1049,8 @@ public class HttpClientBuilder {
cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
.register("rfc2109", new RFC2109SpecFactory())
.register("rfc2965", new RFC2965SpecFactory())
.build();
}

View File

@ -52,11 +52,19 @@ import org.apache.http.util.CharArrayBuffer;
@ThreadSafe
public class DefaultCookieSpec implements CookieSpec {
public enum CompatibilityLevel {
DEFAULT,
IE_MEDIUM_SECURITY
}
private final RFC2965Spec strict;
private final RFC2109Spec obsoleteStrict;
private final NetscapeDraftSpec netscapeDraft;
public DefaultCookieSpec(final String[] datepatterns, final boolean oneHeader) {
public DefaultCookieSpec(
final String[] datepatterns,
final boolean oneHeader,
final CompatibilityLevel compatibilityLevel) {
super();
this.strict = new RFC2965Spec(oneHeader,
new RFC2965VersionAttributeHandler(),
@ -77,13 +85,25 @@ public class DefaultCookieSpec implements CookieSpec {
new BasicCommentHandler());
this.netscapeDraft = new NetscapeDraftSpec(
new BasicDomainHandler(),
new BasicPathHandler(),
compatibilityLevel == CompatibilityLevel.IE_MEDIUM_SECURITY ?
new BasicPathHandler() {
@Override
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException {
// No validation
}
} : new BasicPathHandler(),
new BasicSecureHandler(),
new BasicCommentHandler(),
new BasicExpiresHandler(
datepatterns != null ? datepatterns.clone() : new String[]{NetscapeDraftSpec.EXPIRES_PATTERN}));
}
public DefaultCookieSpec(
final String[] datepatterns,
final boolean oneHeader) {
this(datepatterns, oneHeader, null);
}
public DefaultCookieSpec() {
this(null, false);
}

View File

@ -47,10 +47,9 @@ import org.apache.http.cookie.SM;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.impl.cookie.BasicClientCookie2;
import org.apache.http.impl.cookie.BrowserCompatSpec;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
import org.apache.http.impl.cookie.IgnoreSpecFactory;
import org.apache.http.impl.cookie.NetscapeDraftSpec;
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
import org.apache.http.message.BasicHttpRequest;
@ -83,7 +82,6 @@ public class TestRequestAddCookies {
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
.build();
@ -252,7 +250,7 @@ public class TestRequestAddCookies {
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final RequestConfig config = RequestConfig.custom()
.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
.setCookieSpec(CookieSpecs.NETSCAPE).build();
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();
@ -266,7 +264,7 @@ public class TestRequestAddCookies {
interceptor.process(request, context);
final CookieSpec cookieSpec = context.getCookieSpec();
Assert.assertTrue(cookieSpec instanceof BrowserCompatSpec);
Assert.assertTrue(cookieSpec instanceof NetscapeDraftSpec);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
Assert.assertNotNull(headers1);