Replaced BEST_MATCH with DEFAULT policy

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1620939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-08-27 17:07:34 +00:00
parent 92700fd23b
commit 139529327c
11 changed files with 154 additions and 27 deletions

View File

@ -205,7 +205,7 @@ public class ClientConfiguration {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// Create global request configuration
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.BEST_MATCH)
.setCookieSpec(CookieSpecs.DEFAULT)
.setExpectContinueEnabled(true)
.setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))

View File

@ -0,0 +1,57 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.impl.cookie;
import org.apache.http.annotation.ThreadSafe;
/**
* 'Meta' cookie specification that picks up a cookie policy based on
* the format of cookies sent with the HTTP response.
*
* @deprecated (4.4) use {@link org.apache.http.impl.cookie.DefaultCookieSpec}.
*
* @since 4.0
*/
@ThreadSafe
@Deprecated
public class BestMatchSpec extends DefaultCookieSpec {
public BestMatchSpec(final String[] datepatterns, final boolean oneHeader) {
super(datepatterns, oneHeader);
}
public BestMatchSpec() {
this(null, false);
}
@Override
public String toString() {
return "best-match";
}
}

View File

@ -42,10 +42,12 @@ import org.apache.http.protocol.HttpContext;
* {@link org.apache.http.impl.cookie.BestMatchSpec}. 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 BestMatchSpecFactory implements CookieSpecFactory, CookieSpecProvider {
private final CookieSpec cookieSpec;

View File

@ -55,9 +55,16 @@ public final class CookieSpecs {
/**
* The default 'best match' policy.
* @deprecated (4.4) use {@link #DEFAULT}.
*/
@Deprecated
public static final String BEST_MATCH = "best-match";
/**
* The default policy.
*/
public static final String DEFAULT = "default";
/**
* The policy that ignores cookies.
*/

View File

@ -117,7 +117,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
final RequestConfig config = clientContext.getRequestConfig();
String policy = config.getCookieSpec();
if (policy == null) {
policy = CookieSpecs.BEST_MATCH;
policy = CookieSpecs.DEFAULT;
}
if (this.log.isDebugEnabled()) {
this.log.debug("CookieSpec selected: " + policy);

View File

@ -97,8 +97,8 @@ 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.BestMatchSpecFactory;
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;
@ -1049,7 +1049,7 @@ public class HttpClientBuilder {
Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;
if (cookieSpecRegistryCopy == null) {
cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())

View File

@ -44,19 +44,19 @@ import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;
/**
* 'Meta' cookie specification that picks up a cookie policy based on
* Default cookie specification that picks up the bests matching cookie policy based on
* the format of cookies sent with the HTTP response.
*
* @since 4.0
* @since 4.4
*/
@ThreadSafe
public class BestMatchSpec implements CookieSpec {
public class DefaultCookieSpec implements CookieSpec {
private final RFC2965Spec strict;
private final RFC2109Spec obsoleteStrict;
private final NetscapeDraftSpec netscapeDraft;
public BestMatchSpec(final String[] datepatterns, final boolean oneHeader) {
public DefaultCookieSpec(final String[] datepatterns, final boolean oneHeader) {
super();
this.strict = new RFC2965Spec(oneHeader,
new RFC2965VersionAttributeHandler(),
@ -84,7 +84,7 @@ public class BestMatchSpec implements CookieSpec {
datepatterns != null ? datepatterns.clone() : new String[]{NetscapeDraftSpec.EXPIRES_PATTERN}));
}
public BestMatchSpec() {
public DefaultCookieSpec() {
this(null, false);
}
@ -204,7 +204,7 @@ public class BestMatchSpec implements CookieSpec {
@Override
public String toString() {
return "best-match";
return "default";
}
}

View File

@ -0,0 +1,61 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.impl.cookie;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.protocol.HttpContext;
/**
* {@link org.apache.http.cookie.CookieSpecProvider} implementation that provides an instance of
* {@link BestMatchSpec}. The instance returned by this factory can
* be shared by multiple threads.
*
* @since 4.4
*/
@Immutable
public class DefaultCookieSpecProvider implements CookieSpecProvider {
private final CookieSpec cookieSpec;
public DefaultCookieSpecProvider(final String[] datepatterns, final boolean oneHeader) {
super();
this.cookieSpec = new DefaultCookieSpec(datepatterns, oneHeader);;
}
public DefaultCookieSpecProvider() {
this(null, false);
}
@Override
public CookieSpec create(final HttpContext context) {
return this.cookieSpec;
}
}

View File

@ -47,9 +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.BestMatchSpecFactory;
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.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
@ -81,7 +81,7 @@ public class TestRequestAddCookies {
this.cookieStore.addCookie(cookie2);
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())

View File

@ -37,7 +37,7 @@ import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.SM;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BestMatchSpec;
import org.apache.http.impl.cookie.DefaultCookieSpec;
import org.apache.http.message.BasicHttpResponse;
import org.junit.Assert;
import org.junit.Before;
@ -52,7 +52,7 @@ public class TestResponseProcessCookies {
@Before
public void setUp() throws Exception {
this.cookieOrigin = new CookieOrigin("localhost", 80, "/", false);
this.cookieSpec = new BestMatchSpec();
this.cookieSpec = new DefaultCookieSpec();
this.cookieStore = new BasicCookieStore();
}

View File

@ -44,11 +44,11 @@ import org.junit.Test;
/**
* Test cases for 'best match' cookie policy
*/
public class TestCookieBestMatchSpec {
public class TestDefaultCookieSpec {
@Test
public void testCookieBrowserCompatParsing() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);
// Make sure the lenient (browser compatible) cookie parsing
@ -63,7 +63,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testNetscapeCookieParsing() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie",
@ -80,7 +80,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieStandardCompliantParsing() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);
// Make sure the strict (RFC2965) cookie parsing
@ -113,7 +113,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieStandardCompliantParsingLocalHost() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
final Header header = new BasicHeader("Set-Cookie", "special=\"abcdigh\"; Version=1");
@ -129,7 +129,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieStandardCompliantParsingLocalHost2() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
final Header header = new BasicHeader("Set-Cookie2", "special=\"abcdigh\"; Version=1");
@ -145,7 +145,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieBrowserCompatMatch() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);
// Make sure the lenient (browser compatible) cookie matching
@ -161,7 +161,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieStandardCompliantMatch() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);
// Make sure the strict (RFC2965) cookie matching
@ -182,7 +182,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieBrowserCompatFormatting() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
// Make sure the lenient (browser compatible) cookie formatting
// is used for Netscape style cookies
@ -214,7 +214,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testCookieStandardCompliantFormatting() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec(null, true);
final CookieSpec cookiespec = new DefaultCookieSpec(null, true);
// Make sure the strict (RFC2965) cookie formatting
// is used for Netscape style cookies
@ -249,7 +249,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testInvalidInput() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
try {
cookiespec.parse(null, null);
Assert.fail("IllegalArgumentException must have been thrown");
@ -279,7 +279,7 @@ public class TestCookieBestMatchSpec {
@Test
public void testVersion1CookieWithInvalidExpires() throws Exception {
final CookieSpec cookiespec = new BestMatchSpec();
final CookieSpec cookiespec = new DefaultCookieSpec();
final CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
final Header origHeader = new BasicHeader("Set-Cookie",