Author: olegk
Date: Wed Aug 31 10:11:00 2005
New Revision: 265534

URL: http://svn.apache.org/viewcvs?rev=265534&view=rev
Log:
Cookie version support as defined in RFC2965

Added:
    
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
   (with props)
Modified:
    
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
    
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
    
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java

Modified: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java?rev=265534&r1=265533&r2=265534&view=diff
==============================================================================
--- 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
 (original)
+++ 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
 Wed Aug 31 10:11:00 2005
@@ -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,24 +1192,11 @@
                     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;
     }
 
     /**

Modified: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java?rev=265534&r1=265533&r2=265534&view=diff
==============================================================================
--- 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
 (original)
+++ 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java
 Wed Aug 31 10:11:00 2005
@@ -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;
-    }
+    
 }

Added: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java?rev=265534&view=auto
==============================================================================
--- 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
 (added)
+++ 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
 Wed Aug 31 10:11:00 2005
@@ -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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.httpclient.cookie;
+
+import org.apache.commons.httpclient.Header;
+
+/**
+ * Defines cookie specification specific capabilities
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @since 3.1
+ */
+public interface CookieVersionSupport {    
+
+    int getVersion();
+    
+    Header getVersionHeader();
+
+}

Propchange: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieVersionSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java?rev=265534&r1=265533&r2=265534&view=diff
==============================================================================
--- 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java
 (original)
+++ 
jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java
 Wed Aug 31 10:11:00 2005
@@ -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);
     }
 }
+



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to