mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-17 07:26:47 +00:00
Initialize singleton cookie specs lazily
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1623733 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4478df7a70
commit
d568ebdbf3
@ -37,10 +37,12 @@
|
|||||||
/**
|
/**
|
||||||
* {@link CookieSpecProvider} implementation that ignores all cookies.
|
* {@link CookieSpecProvider} implementation that ignores all cookies.
|
||||||
*
|
*
|
||||||
|
* @deprecated (4.4) Use {@link org.apache.http.impl.cookie.IgnoreSpecProvider}.
|
||||||
|
*
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@SuppressWarnings("deprecation")
|
@Deprecated
|
||||||
public class IgnoreSpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
public class IgnoreSpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
||||||
|
|
||||||
public IgnoreSpecFactory() {
|
public IgnoreSpecFactory() {
|
@ -42,10 +42,12 @@
|
|||||||
* {@link org.apache.http.impl.cookie.NetscapeDraftSpec}. The instance returned by this factory
|
* {@link org.apache.http.impl.cookie.NetscapeDraftSpec}. The instance returned by this factory
|
||||||
* can be shared by multiple threads.
|
* can be shared by multiple threads.
|
||||||
*
|
*
|
||||||
|
* @deprecated (4.4) Use {@link org.apache.http.impl.cookie.NetscapeDraftSpecProvider}.
|
||||||
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@SuppressWarnings("deprecation")
|
@Deprecated
|
||||||
public class NetscapeDraftSpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
public class NetscapeDraftSpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
||||||
|
|
||||||
private final CookieSpec cookieSpec;
|
private final CookieSpec cookieSpec;
|
@ -42,10 +42,12 @@
|
|||||||
* {@link org.apache.http.impl.cookie.RFC2109Spec}. The instance returned by this factory
|
* {@link org.apache.http.impl.cookie.RFC2109Spec}. The instance returned by this factory
|
||||||
* can be shared by multiple threads.
|
* can be shared by multiple threads.
|
||||||
*
|
*
|
||||||
|
* @deprecated (4.4) Use {@link org.apache.http.impl.cookie.RFC2109SpecProvider}.
|
||||||
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@SuppressWarnings("deprecation")
|
@Deprecated
|
||||||
public class RFC2109SpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
public class RFC2109SpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
||||||
|
|
||||||
private final CookieSpec cookieSpec;
|
private final CookieSpec cookieSpec;
|
@ -42,10 +42,12 @@
|
|||||||
* {@link org.apache.http.impl.cookie.RFC2965Spec}. The instance returned by this factory can
|
* {@link org.apache.http.impl.cookie.RFC2965Spec}. The instance returned by this factory can
|
||||||
* be shared by multiple threads.
|
* be shared by multiple threads.
|
||||||
*
|
*
|
||||||
|
* @deprecated (4.4) Use {@link org.apache.http.impl.cookie.RFC2965SpecProvider}.
|
||||||
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
@Immutable
|
@Immutable
|
||||||
@SuppressWarnings("deprecation")
|
@Deprecated
|
||||||
public class RFC2965SpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
public class RFC2965SpecFactory implements CookieSpecFactory, CookieSpecProvider {
|
||||||
|
|
||||||
private final CookieSpec cookieSpec;
|
private final CookieSpec cookieSpec;
|
@ -98,9 +98,9 @@
|
|||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
|
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
|
||||||
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
|
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
|
||||||
import org.apache.http.impl.cookie.IgnoreSpecFactory;
|
import org.apache.http.impl.cookie.IgnoreSpecProvider;
|
||||||
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
|
import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
|
||||||
import org.apache.http.impl.cookie.RFC2965SpecFactory;
|
import org.apache.http.impl.cookie.RFC2965SpecProvider;
|
||||||
import org.apache.http.impl.execchain.BackoffStrategyExec;
|
import org.apache.http.impl.execchain.BackoffStrategyExec;
|
||||||
import org.apache.http.impl.execchain.ClientExecChain;
|
import org.apache.http.impl.execchain.ClientExecChain;
|
||||||
import org.apache.http.impl.execchain.MainClientExec;
|
import org.apache.http.impl.execchain.MainClientExec;
|
||||||
@ -1048,9 +1048,9 @@ public CloseableHttpClient build() {
|
|||||||
if (cookieSpecRegistryCopy == null) {
|
if (cookieSpecRegistryCopy == null) {
|
||||||
cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
|
cookieSpecRegistryCopy = RegistryBuilder.<CookieSpecProvider>create()
|
||||||
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
|
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
|
||||||
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
|
.register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
|
||||||
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
|
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
|
||||||
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
|
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,19 +52,22 @@
|
|||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public class DefaultCookieSpec implements CookieSpec {
|
public class DefaultCookieSpec implements CookieSpec {
|
||||||
|
|
||||||
public enum CompatibilityLevel {
|
|
||||||
DEFAULT,
|
|
||||||
IE_MEDIUM_SECURITY
|
|
||||||
}
|
|
||||||
|
|
||||||
private final RFC2965Spec strict;
|
private final RFC2965Spec strict;
|
||||||
private final RFC2109Spec obsoleteStrict;
|
private final RFC2109Spec obsoleteStrict;
|
||||||
private final NetscapeDraftSpec netscapeDraft;
|
private final NetscapeDraftSpec netscapeDraft;
|
||||||
|
|
||||||
|
DefaultCookieSpec(
|
||||||
|
final RFC2965Spec strict,
|
||||||
|
final RFC2109Spec obsoleteStrict,
|
||||||
|
final NetscapeDraftSpec netscapeDraft) {
|
||||||
|
this.strict = strict;
|
||||||
|
this.obsoleteStrict = obsoleteStrict;
|
||||||
|
this.netscapeDraft = netscapeDraft;
|
||||||
|
}
|
||||||
|
|
||||||
public DefaultCookieSpec(
|
public DefaultCookieSpec(
|
||||||
final String[] datepatterns,
|
final String[] datepatterns,
|
||||||
final boolean oneHeader,
|
final boolean oneHeader) {
|
||||||
final CompatibilityLevel compatibilityLevel) {
|
|
||||||
super();
|
super();
|
||||||
this.strict = new RFC2965Spec(oneHeader,
|
this.strict = new RFC2965Spec(oneHeader,
|
||||||
new RFC2965VersionAttributeHandler(),
|
new RFC2965VersionAttributeHandler(),
|
||||||
@ -85,25 +88,13 @@ public DefaultCookieSpec(
|
|||||||
new BasicCommentHandler());
|
new BasicCommentHandler());
|
||||||
this.netscapeDraft = new NetscapeDraftSpec(
|
this.netscapeDraft = new NetscapeDraftSpec(
|
||||||
new BasicDomainHandler(),
|
new BasicDomainHandler(),
|
||||||
compatibilityLevel == CompatibilityLevel.IE_MEDIUM_SECURITY ?
|
new BasicPathHandler(),
|
||||||
new BasicPathHandler() {
|
|
||||||
@Override
|
|
||||||
public void validate(final Cookie cookie, final CookieOrigin origin) throws MalformedCookieException {
|
|
||||||
// No validation
|
|
||||||
}
|
|
||||||
} : new BasicPathHandler(),
|
|
||||||
new BasicSecureHandler(),
|
new BasicSecureHandler(),
|
||||||
new BasicCommentHandler(),
|
new BasicCommentHandler(),
|
||||||
new BasicExpiresHandler(
|
new BasicExpiresHandler(
|
||||||
datepatterns != null ? datepatterns.clone() : new String[]{NetscapeDraftSpec.EXPIRES_PATTERN}));
|
datepatterns != null ? datepatterns.clone() : new String[]{NetscapeDraftSpec.EXPIRES_PATTERN}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultCookieSpec(
|
|
||||||
final String[] datepatterns,
|
|
||||||
final boolean oneHeader) {
|
|
||||||
this(datepatterns, oneHeader, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultCookieSpec() {
|
public DefaultCookieSpec() {
|
||||||
this(null, false);
|
this(null, false);
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,11 @@
|
|||||||
package org.apache.http.impl.cookie;
|
package org.apache.http.impl.cookie;
|
||||||
|
|
||||||
import org.apache.http.annotation.Immutable;
|
import org.apache.http.annotation.Immutable;
|
||||||
|
import org.apache.http.cookie.Cookie;
|
||||||
|
import org.apache.http.cookie.CookieOrigin;
|
||||||
import org.apache.http.cookie.CookieSpec;
|
import org.apache.http.cookie.CookieSpec;
|
||||||
import org.apache.http.cookie.CookieSpecProvider;
|
import org.apache.http.cookie.CookieSpecProvider;
|
||||||
|
import org.apache.http.cookie.MalformedCookieException;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,19 +45,72 @@
|
|||||||
@Immutable
|
@Immutable
|
||||||
public class DefaultCookieSpecProvider implements CookieSpecProvider {
|
public class DefaultCookieSpecProvider implements CookieSpecProvider {
|
||||||
|
|
||||||
private final CookieSpec cookieSpec;
|
public enum CompatibilityLevel {
|
||||||
|
DEFAULT,
|
||||||
|
IE_MEDIUM_SECURITY
|
||||||
|
}
|
||||||
|
|
||||||
public DefaultCookieSpecProvider(final String[] datepatterns, final boolean oneHeader) {
|
private final CompatibilityLevel compatibilityLevel;
|
||||||
|
private final String[] datepatterns;
|
||||||
|
private final boolean oneHeader;
|
||||||
|
|
||||||
|
private volatile CookieSpec cookieSpec;
|
||||||
|
|
||||||
|
public DefaultCookieSpecProvider(
|
||||||
|
final CompatibilityLevel compatibilityLevel,
|
||||||
|
final String[] datepatterns,
|
||||||
|
final boolean oneHeader) {
|
||||||
super();
|
super();
|
||||||
this.cookieSpec = new DefaultCookieSpec(datepatterns, oneHeader);;
|
this.compatibilityLevel = compatibilityLevel != null ? compatibilityLevel : CompatibilityLevel.DEFAULT;
|
||||||
|
this.datepatterns = datepatterns;
|
||||||
|
this.oneHeader = oneHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultCookieSpecProvider() {
|
public DefaultCookieSpecProvider() {
|
||||||
this(null, false);
|
this(CompatibilityLevel.DEFAULT, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CookieSpec create(final HttpContext context) {
|
public CookieSpec create(final HttpContext context) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
final RFC2965Spec strict = new RFC2965Spec(this.oneHeader,
|
||||||
|
new RFC2965VersionAttributeHandler(),
|
||||||
|
new BasicPathHandler(),
|
||||||
|
new RFC2965DomainAttributeHandler(),
|
||||||
|
new RFC2965PortAttributeHandler(),
|
||||||
|
new BasicMaxAgeHandler(),
|
||||||
|
new BasicSecureHandler(),
|
||||||
|
new BasicCommentHandler(),
|
||||||
|
new RFC2965CommentUrlAttributeHandler(),
|
||||||
|
new RFC2965DiscardAttributeHandler());
|
||||||
|
final RFC2109Spec obsoleteStrict = new RFC2109Spec(this.oneHeader,
|
||||||
|
new RFC2109VersionHandler(),
|
||||||
|
new BasicPathHandler(),
|
||||||
|
new RFC2109DomainHandler(),
|
||||||
|
new BasicMaxAgeHandler(),
|
||||||
|
new BasicSecureHandler(),
|
||||||
|
new BasicCommentHandler());
|
||||||
|
final NetscapeDraftSpec netscapeDraft = new NetscapeDraftSpec(
|
||||||
|
new BasicDomainHandler(),
|
||||||
|
this.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(this.datepatterns != null ? this.datepatterns.clone() :
|
||||||
|
new String[]{NetscapeDraftSpec.EXPIRES_PATTERN}));
|
||||||
|
this.cookieSpec = new DefaultCookieSpec(strict, obsoleteStrict, netscapeDraft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return this.cookieSpec;
|
return this.cookieSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 ignores all cookies.
|
||||||
|
*
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public class IgnoreSpecProvider implements CookieSpecProvider {
|
||||||
|
|
||||||
|
private volatile CookieSpec cookieSpec;
|
||||||
|
|
||||||
|
public IgnoreSpecProvider() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CookieSpec create(final HttpContext context) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
this.cookieSpec = new IgnoreSpec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.cookieSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* 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 NetscapeDraftSpec}. The instance returned by this factory
|
||||||
|
* can be shared by multiple threads.
|
||||||
|
*
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public class NetscapeDraftSpecProvider implements CookieSpecProvider {
|
||||||
|
|
||||||
|
private final String[] datepatterns;
|
||||||
|
|
||||||
|
private volatile CookieSpec cookieSpec;
|
||||||
|
|
||||||
|
public NetscapeDraftSpecProvider(final String[] datepatterns) {
|
||||||
|
super();
|
||||||
|
this.datepatterns = datepatterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetscapeDraftSpecProvider() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CookieSpec create(final HttpContext context) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
this.cookieSpec = new NetscapeDraftSpec(this.datepatterns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.cookieSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* 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 RFC2109Spec}. The instance returned by this factory
|
||||||
|
* can be shared by multiple threads.
|
||||||
|
*
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public class RFC2109SpecProvider implements CookieSpecProvider {
|
||||||
|
|
||||||
|
private final boolean oneHeader;
|
||||||
|
|
||||||
|
private volatile CookieSpec cookieSpec;
|
||||||
|
|
||||||
|
public RFC2109SpecProvider(final boolean oneHeader) {
|
||||||
|
super();
|
||||||
|
this.oneHeader = oneHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RFC2109SpecProvider() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CookieSpec create(final HttpContext context) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
this.cookieSpec = new RFC2109Spec(null, this.oneHeader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.cookieSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* 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 RFC2965Spec}. The instance returned by this factory can
|
||||||
|
* be shared by multiple threads.
|
||||||
|
*
|
||||||
|
* @since 4.4
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public class RFC2965SpecProvider implements CookieSpecProvider {
|
||||||
|
|
||||||
|
private final boolean oneHeader;
|
||||||
|
|
||||||
|
private volatile CookieSpec cookieSpec;
|
||||||
|
|
||||||
|
public RFC2965SpecProvider(final boolean oneHeader) {
|
||||||
|
super();
|
||||||
|
this.oneHeader = oneHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RFC2965SpecProvider() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CookieSpec create(final HttpContext context) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (cookieSpec == null) {
|
||||||
|
this.cookieSpec = new RFC2965Spec(null, this.oneHeader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.cookieSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -48,10 +48,10 @@
|
|||||||
import org.apache.http.impl.cookie.BasicClientCookie;
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
||||||
import org.apache.http.impl.cookie.BasicClientCookie2;
|
import org.apache.http.impl.cookie.BasicClientCookie2;
|
||||||
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
|
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
|
||||||
import org.apache.http.impl.cookie.IgnoreSpecFactory;
|
import org.apache.http.impl.cookie.IgnoreSpecProvider;
|
||||||
import org.apache.http.impl.cookie.NetscapeDraftSpec;
|
import org.apache.http.impl.cookie.NetscapeDraftSpec;
|
||||||
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
|
import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
|
||||||
import org.apache.http.impl.cookie.RFC2965SpecFactory;
|
import org.apache.http.impl.cookie.RFC2965SpecProvider;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.protocol.HttpCoreContext;
|
import org.apache.http.protocol.HttpCoreContext;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -81,9 +81,9 @@ public void setUp() {
|
|||||||
|
|
||||||
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
|
this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
|
||||||
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
|
.register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
|
||||||
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
|
.register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
|
||||||
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
|
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
|
||||||
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
|
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user