Index: src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java =================================================================== --- src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java (revision 264739) +++ src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java (working copy) @@ -320,11 +320,5 @@ public static CookieSpec getCompatibilitySpec() { return getSpecByPolicy(COMPATIBILITY); } - - public static int getCookieVersionBySpec(CookieSpec spec) { - if ((spec instanceof RFC2109Spec) || - (spec instanceof RFC2965Spec)) - return 1; - return 0; - } + } Index: src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java =================================================================== --- src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java (revision 264739) +++ src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java (working copy) @@ -44,7 +44,7 @@ * @since 3.0 */ -public class RFC2965Spec extends CookieSpecBase { +public class RFC2965Spec extends CookieSpecBase implements CookieVersionSupport { /** * Cookie Response Header name for cookies processed @@ -1192,5 +1192,20 @@ public void format(StringBuffer buffer, Cookie cookie) { formatter.format(buffer, new NameValuePair("$Version", "1")); } + + } + + public int getVersion() { + return 1; + } + + public Header getVersionHeader() { + ParameterFormatter formatter = new ParameterFormatter(); + StringBuffer buffer = new StringBuffer(); + formatter.format(buffer, new NameValuePair("$Version", + Integer.toString(getVersion()))); + return new Header("Cookie2", buffer.toString(), true); + } } + Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== --- src/java/org/apache/commons/httpclient/HttpMethodBase.java (revision 264739) +++ src/java/org/apache/commons/httpclient/HttpMethodBase.java (working copy) @@ -39,6 +39,7 @@ import org.apache.commons.httpclient.auth.AuthState; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.cookie.CookieSpec; +import org.apache.commons.httpclient.cookie.CookieVersionSupport; import org.apache.commons.httpclient.cookie.MalformedCookieException; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; @@ -1191,27 +1192,14 @@ getRequestHeaderGroup().addHeader(new Header("Cookie", s, true)); } } - // add a Cookie2 request header specifying the highest cookie version - // this client understands. There is no harm in always sending it. - // TODO (jain): need to refactor this into spec class somehow - getRequestHeaderGroup().addHeader(buildCookie2RequestHeader(matcher)); + if (matcher instanceof CookieVersionSupport) { + Header ver = ((CookieVersionSupport)matcher).getVersionHeader(); + getRequestHeaderGroup().addHeader(ver); + } } } /** - * Builds Cookie2 request header. - * @param spec - */ - protected Header buildCookie2RequestHeader(CookieSpec spec) { - ParameterFormatter formatter = new ParameterFormatter(); - StringBuffer buffer = new StringBuffer(); - formatter.format(buffer, new NameValuePair("$Version", - Integer.toString(CookiePolicy.getCookieVersionBySpec(spec)))); - Header header = new Header("Cookie2", buffer.toString(), true); - return header; - } - - /** * Generates Host request header, as long as no Host request * header already exists. * Index: src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java =================================================================== --- /dev/null 2005-08-30 12:26:03.783827300 +0200 +++ src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java 2005-08-30 12:14:14.447712700 +0200 @@ -0,0 +1,47 @@ +/* + * $Header: $ + * $Revision: $ + * $Date: $ + * + * ==================================================================== + * + * Copyright 2002-2004 The Apache Software Foundation + * + * Licensed 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 + * . + * + */ + +package org.apache.commons.httpclient.cookie; + +import org.apache.commons.httpclient.Header; + +/** + * Defines cookie specification specific capabilities + * + * @author Oleg Kalnichevski + * + * @since 3.1 + */ +public interface CookieVersionSupport { + + int getVersion(); + + Header getVersionHeader(); + +}