HTTPCLIENT-1030) Implement "ignoreCookies" CookieSpec

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1042225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-12-04 19:01:02 +00:00
parent e6af69f2e4
commit d1f6c23e10
4 changed files with 121 additions and 0 deletions

View File

@ -63,6 +63,13 @@ public final class CookiePolicy {
*/ */
public static final String BEST_MATCH = "best-match"; public static final String BEST_MATCH = "best-match";
/**
* The policy that ignores cookies.
*
* @since 4.1-beta1
*/
public static final String IGNORE_COOKIES = "ignoreCookies";
private CookiePolicy() { private CookiePolicy() {
super(); super();
} }

View File

@ -67,6 +67,7 @@ import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
import org.apache.http.impl.conn.SingleClientConnManager; import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.impl.cookie.BestMatchSpecFactory; import org.apache.http.impl.cookie.BestMatchSpecFactory;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory; import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
import org.apache.http.impl.cookie.IgnoreSpecFactory;
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory; import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2109SpecFactory; import org.apache.http.impl.cookie.RFC2109SpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory; import org.apache.http.impl.cookie.RFC2965SpecFactory;
@ -326,6 +327,9 @@ public class DefaultHttpClient extends AbstractHttpClient {
registry.register( registry.register(
CookiePolicy.RFC_2965, CookiePolicy.RFC_2965,
new RFC2965SpecFactory()); new RFC2965SpecFactory());
registry.register(
CookiePolicy.IGNORE_COOKIES,
new IgnoreSpecFactory());
return registry; return registry;
} }

View File

@ -0,0 +1,63 @@
/*
* ====================================================================
* 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 java.util.Collections;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
/**
* CookieSpec that ignores all cookies
*
* @since 4.1
*/
@NotThreadSafe // superclass is @NotThreadSafe
public class IgnoreSpec extends CookieSpecBase {
public int getVersion() {
return 0;
}
public List<Cookie> parse(Header header, CookieOrigin origin)
throws MalformedCookieException {
return Collections.emptyList();
}
public List<Header> formatCookies(List<Cookie> cookies) {
return Collections.emptyList();
}
public Header getVersionHeader() {
return null;
}
}

View File

@ -0,0 +1,47 @@
/*
* ====================================================================
* 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.CookieSpecFactory;
import org.apache.http.params.HttpParams;
/**
* {@link CookieSpecFactory} implementation that ignores all cookies.
*
* @since 4.1
*/
@Immutable
public class IgnoreSpecFactory implements CookieSpecFactory {
public CookieSpec newInstance(final HttpParams params) {
return new IgnoreSpec();
}
}