commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r264149 [1/3] - in /jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src: java/org/apache/commons/httpclient/ java/org/apache/commons/httpclient/cookie/ test/org/apache/commons/httpclient/cookie/
Date Mon, 29 Aug 2005 14:28:43 GMT
Author: olegk
Date: Mon Aug 29 07:28:21 2005
New Revision: 264149

URL: http://svn.apache.org/viewcvs?rev=264149&view=rev
Log:
Corrective patch by Samit Jain based on the initial feedback from other contributors

Added:
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/Cookie2.java
  (with props)
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieAttributeHandler.java
  (with props)
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookie2.java
  (with props)
Modified:
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Cookie.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Header.java
    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/CookieSpec.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2965Spec.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieRFC2965Spec.java

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Cookie.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Cookie.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Cookie.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Cookie.java
Mon Aug 29 07:28:21 2005
@@ -63,17 +63,6 @@
  */
 public class Cookie extends NameValuePair implements Serializable, Comparator {
 
-    // string constants for cookie attributes
-    public static final String DOMAIN = "domain";
-    public static final String PATH = "path";
-    public static final String PORT = "port";
-    public static final String VERSION = "version";
-    public static final String SECURE = "secure";
-    public static final String MAXAGE = "max-age";
-    public static final String COMMENT = "comment";
-    public static final String COMMENTURL = "commenturl";
-    public static final String DISCARD = "discard";
-
     // ----------------------------------------------------------- Constructors
 
     /**
@@ -156,32 +145,6 @@
     }
 
     /**
-     * Creates a cookie with the given name, value, domain attribute,
-     * path attribute, expiration attribute, secure attribute, and ports
-     * attribute.
-     *
-     * @param name    the cookie name
-     * @param value   the cookie value
-     * @param domain  the domain this cookie can be sent to
-     * @param path    the path prefix for which this cookie can be sent
-     * @param expires the {@link Date} at which this cookie expires,
-     *                or <tt>null</tt> if the cookie expires at the end
-     *                of the session
-     * @param secure if true this cookie can only be sent over secure
-     * connections
-     * @param ports   the ports for which this cookie can be sent
-     * @throws IllegalArgumentException If cookie name is null or blank,
-     *   cookie name contains a blank, or cookie name starts with character $
-     *
-     */
-    public Cookie(String domain, String name, String value,
-                  String path, Date expires, boolean secure, int[] ports) {
-
-        this(domain, name, value, path, expires, secure);
-        this.setPorts(ports);
-    }
-
-    /**
      * Returns the comment describing the purpose of this cookie, or
      * <tt>null</tt> if no such comment has been defined.
      * 
@@ -205,50 +168,6 @@
         cookieComment = comment;
     }
 
-   /**
-     * If a user agent (web browser) presents this cookie to a user, the
-     * cookie's purpose will be described by the information at this URL.
-     *
-     * @see #setCommentURL(String)
-     */
-    public String getCommentURL() {
-        return cookieCommentURL;
-    }
-
-   /**
-     * If a user agent (web browser) presents this cookie to a user, the
-     * cookie's purpose will be described by the information at this URL.
-     *
-     * @param commentURL
-     *
-     * @see #getCommentURL()
-     */
-    public void setCommentURL(String commentURL) {
-        this.cookieCommentURL = commentURL;
-    }
-
-   /**
-     * Get the Port attribute. It restricts the ports to which a cookie
-     * may be returned in a Cookie request header.
-     *
-     * @see #setPorts(int[])
-     */
-    public int[] getPorts() {
-        return cookiePorts;
-    }
-
-   /**
-     * Set the Port attribute. It restricts the ports to which a cookie
-     * may be returned in a Cookie request header.
-     *
-     * @param ports
-     *
-     * @see #getPorts()
-     */
-    public void setPorts(int[] ports) {
-        this.cookiePorts = ports;
-    }
-
     /**
      * Returns the expiration {@link Date} of the cookie, or <tt>null</tt>
      * if none exists.
@@ -279,15 +198,6 @@
         cookieExpiryDate = expiryDate;
     }
 
-    /**
-     * Set the Discard attribute.
-     *
-     * @see #isPersistent()
-     *
-     */
-    public void setDiscard(boolean toDiscard) {
-        discard = toDiscard;
-    }
 
     /**
      * Returns <tt>false</tt> if the cookie should be discarded at the end
@@ -297,7 +207,7 @@
      *         of the "session"; <tt>true</tt> otherwise
      */
     public boolean isPersistent() {
-        return (null != cookieExpiryDate) && !discard;
+        return (null != cookieExpiryDate);
     }
 
 
@@ -403,15 +313,13 @@
     }
 
     /**
-     * Returns true if this cookie has expired. Also returns
-     * true for a session cookie (discard=true).
+     * Returns true if this cookie has expired.
      * 
      * @return <tt>true</tt> if the cookie has expired.
      */
     public boolean isExpired() {
-        return (cookieExpiryDate != null &&
-                cookieExpiryDate.getTime() <= System.currentTimeMillis())
-               || discard;
+        return (cookieExpiryDate != null  
+            && cookieExpiryDate.getTime() <= System.currentTimeMillis());
     }
 
     /**
@@ -429,18 +337,11 @@
 
     /**
      * Indicates whether the cookie had a path specified in a 
-     * path attribute of the <tt>Set-Cookie</tt> header. This property
-     * has two uses:
-     * <ul>
-     * <li>This value is important for generating the <tt>Cookie</tt>
-     * header because some cookie specifications require that the
-     * <tt>Cookie</tt> header should only include a path attribute if
-     * the cookie's path was specified in the <tt>Set-Cookie</tt> header.
-     * </li>
-     * <li>This also ensures that if an attribute appears more than once in
-     * a cookie response header, the first appearance of the attribute is used.
-     * </li>
-     * </ul>
+     * path attribute of the <tt>Set-Cookie</tt> header. This value
+     * is important for generating the <tt>Cookie</tt> header because 
+     * some cookie specifications require that the <tt>Cookie</tt> header 
+     * should only include a path attribute if the cookie's path 
+     * was specified in the <tt>Set-Cookie</tt> header.
      *
      * @param value <tt>true</tt> if the cookie's path was explicitly 
      * set, <tt>false</tt> otherwise.
@@ -466,18 +367,12 @@
 
     /**
      * Indicates whether the cookie had a domain specified in a 
-     * domain attribute of the <tt>Set-Cookie</tt> header. This property
-     * has two uses:
-     * <ul>
-     * <li>This value is important for generating the <tt>Cookie</tt> header
-     * because some cookie specifications require that the <tt>Cookie</tt> header
+     * domain attribute of the <tt>Set-Cookie</tt> header. This value
+     * is important for generating the <tt>Cookie</tt> header because 
+     * some cookie specifications require that the <tt>Cookie</tt> header 
      * should only include a domain attribute if the cookie's domain 
      * was specified in the <tt>Set-Cookie</tt> header.
-     * </li>
-     * <li>This also ensures that if an attribute appears more than once in
-     * a cookie response header, the first appearance of the attribute is used.
-     * </li>
-     * </ul>
+     *
      * @param value <tt>true</tt> if the cookie's domain was explicitly 
      * set, <tt>false</tt> otherwise.
      *
@@ -501,82 +396,6 @@
     }
 
     /**
-     * Indicates whether the cookie had a ports list specified in the
-     * Port attribute of the <tt>Set-Cookie2</tt> header. This ensures
-     * that if an attribute appears more than once in a cookie response
-     * header, the first appearance of the attribute is used.
-     *
-     * @param value <tt>true</tt> if the cookie's ports were explicitly
-     * set, <tt>false</tt> otherwise.
-     *
-     * @see #isPortAttributeSpecified
-     */
-    public void setPortAttributeSpecified(boolean value) {
-        hasPortAttribute = value;
-    }
-
-    /**
-     * Returns <tt>true</tt> if cookie's ports were set via the Port
-     * attribute in the <tt>Set-Cookie2</tt> header.
-     *
-     * @return <tt>true</tt> if the cookie's ports were explicitly
-     * set, <tt>false</tt> otherwise.
-     *
-     * @see #setPortAttributeSpecified
-     */
-    public boolean isPortAttributeSpecified() {
-        return hasPortAttribute;
-    }
-
-    /**
-     * Indicates whether the Port attribute in <tt>Set-Cookie2</tt> header
-     * is blank.
-     *
-     * @param value
-     *
-     * @see #isPortAttributeBlank
-     */
-    public void setPortAttributeBlank(boolean value) {
-        isPortAttributeBlank = value;
-    }
-
-    /**
-     * Returns <tt>true</tt> if Port attribute in <tt>Set-Cookie2</tt>
header
-     * did not have any value.
-     *
-     * @return <tt>true</tt> if Port attribute in <tt>Set-Cookie2</tt>
header
-     * did not have any value.
-     *
-     * @see #setPortAttributeBlank
-     */
-    public boolean isPortAttributeBlank() {
-        return isPortAttributeBlank;
-    }
-
-    /**
-     * Returns the response header name this cookie was obtained from.
-     * Currently must be either 'set-cookie' or set-cookie2'.
-     *
-     * @return response header name
-     * @see #setHeaderName(String)
-     */
-    public String getHeaderName() {
-        return headerName;
-    }
-
-    /**
-     * Sets the header name of this cookie.
-     *
-     * @param headerName Currently must be either 'set-cookie' or
-     * set-cookie2'.
-     * @see #getHeaderName()
-     */
-    public void setHeaderName(String headerName) {
-        this.headerName = headerName;
-    }
-
-
-    /**
      * Returns a hash code in keeping with the
      * {@link Object#hashCode} general hashCode contract.
      * @return A hash code
@@ -679,72 +498,37 @@
 
    // ----------------------------------------------------- Instance Variables
 
-    /** Comment attribute. */
-    private String  cookieComment;
-
-    /**
-     * Comment URL attribute
-     * Note: Required for RFC 2965 cookie specification.
-     */
-    private String cookieCommentURL;
-
-    /** Domain attribute. */
-    private String  cookieDomain;
-
-    /**
-     * Port attribute.
-     * Note: Required for RFC 2965 cookie specification.
-     */
-    private int[] cookiePorts;
-
-    /** Expiration {@link Date}. */
-    private Date    cookieExpiryDate;
-
-    /**
-     * Discard attribute.
-     * Note: Required for RFC 2965 cookie specification.
-     */
-    private boolean discard = false;
-
-    /** Path attribute. */
-    private String  cookiePath;
+   /** Comment attribute. */
+   private String  cookieComment;
 
-    /** My secure flag. */
-    private boolean isSecure;
+   /** Domain attribute. */
+   private String  cookieDomain;
 
-    /**
-     * the name of the response header this cookie was obtained from.
-     */
-    private String headerName;
+   /** Expiration {@link Date}. */
+   private Date    cookieExpiryDate;
 
-    /**
-     * Specifies if the set-cookie header included a Path attribute for this
-     * cookie
-     */
-    private boolean hasPathAttribute = false;
+   /** Path attribute. */
+   private String  cookiePath;
 
-    /**
-     * Specifies if the set-cookie header included a Domain attribute for this
-     * cookie
-     */
-    private boolean hasDomainAttribute = false;
+   /** My secure flag. */
+   private boolean isSecure;
 
-    /**
-     * Specifies if the set-cookie2 header included a Port attribute for this
-     * cookie
-     */
-    private boolean hasPortAttribute = false;
+   /**
+    * Specifies if the set-cookie header included a Path attribute for this
+    * cookie
+    */
+   private boolean hasPathAttribute = false;
 
-    /**
-     * Specifies if the set-cookie2 header's Port attribute did not have
-     * any value.
-     */
-    private boolean isPortAttributeBlank = false;
+   /**
+    * Specifies if the set-cookie header included a Domain attribute for this
+    * cookie
+    */
+   private boolean hasDomainAttribute = false;
 
-    /** The version of the cookie specification I was created from. */
-    private int     cookieVersion = -1;
+   /** The version of the cookie specification I was created from. */
+   private int     cookieVersion = 0;
 
-    // -------------------------------------------------------------- Constants
+   // -------------------------------------------------------------- Constants
 
    /** 
     * Collator for Cookie comparisons.  Could be replaced with references to

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Header.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Header.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Header.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/Header.java
Mon Aug 29 07:28:21 2005
@@ -46,10 +46,6 @@
      */
     private boolean isAutogenerated = false;
 
-    public static String SET_COOKIE_KEY = "set-cookie";
-
-    public static String SET_COOKIE2_KEY = "set-cookie2";
-    
     /**
      * Default constructor.
      */

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=264149&r1=264148&r2=264149&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
Mon Aug 29 07:28:21 2005
@@ -1198,12 +1198,15 @@
         }
     }
 
-    Header buildCookie2RequestHeader(CookieSpec spec) {
+    /**
+     * 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(spec.getCookieVersion())));
+        formatter.format(buffer, new NameValuePair("$Version",
+                Integer.toString(CookiePolicy.getCookieVersionBySpec(spec))));
         Header header = new Header("Cookie2", buffer.toString(), true);
         return header;
     }
@@ -1512,7 +1515,6 @@
             Header header = headers[i];
             Cookie[] cookies = null;
             try {
-                System.out.println("(jain) Header[" + i + "]: " + headers[i]);
                 cookies = parser.parse(
                   host,
                   conn.getPort(),
@@ -1530,9 +1532,6 @@
                 for (int j = 0; j < cookies.length; j++) {
                     Cookie cookie = cookies[j];
                     try {
-                        System.out.println("(jain) Cookie [" + j + "]: " +
-                                           cookies[j].getName() + " = " +
-                                           cookies[j].getValue() + " has version " + cookies[j].getVersion());
                         parser.validate(
                           host,
                           conn.getPort(),

Added: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/Cookie2.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/Cookie2.java?rev=264149&view=auto
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/Cookie2.java
(added)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/Cookie2.java
Mon Aug 29 07:28:21 2005
@@ -0,0 +1,367 @@
+/*
+ * $Header: /cvsroot/httpc-cookie2/httpc-cookie2/httpcookie2SVN-patch.082805-2100.diff,v
1.1 2005/08/29 05:01:58 sjain700 Exp $
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-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 java.util.Date;
+
+import org.apache.commons.httpclient.Cookie;
+
+/**
+ * <p>
+ * Cookie class for {@link org.apache.commons.httpclient.cookie.RFC2965Spec}
+ * cookie specification. It extends {@link Cookie} class and adds newer cookie
+ * attributes and functions required for this specification.
+ * </p>
+ *
+ * @author Samit Jain (jain.samit@gmail.com)
+ */
+public class Cookie2 extends Cookie {
+
+    // string constants for cookie attributes
+    public static final String DOMAIN = "domain";
+    public static final String PATH = "path";
+    public static final String PORT = "port";
+    public static final String VERSION = "version";
+    public static final String SECURE = "secure";
+    public static final String MAXAGE = "max-age";
+    public static final String COMMENT = "comment";
+    public static final String COMMENTURL = "commenturl";
+    public static final String DISCARD = "discard";
+
+    public static final String COOKIE_NAME_KEY = "cookieName";
+
+    /**
+     * Default constructor. Creates a blank cookie
+     */
+    public Cookie2() {
+        super(null, "noname", null, null, null, false);
+    }
+
+    /**
+     * Creates a cookie with the given name, value and domain attribute.
+     *
+     * @param name    the cookie name
+     * @param value   the cookie value
+     * @param domain  the domain this cookie can be sent to
+     */
+    public Cookie2(String domain, String name, String value) {
+        super(domain, name, value);
+    }
+
+    /**
+     * Creates a cookie with the given name, value, domain attribute,
+     * path attribute, expiration attribute, and secure attribute
+     *
+     * @param name    the cookie name
+     * @param value   the cookie value
+     * @param domain  the domain this cookie can be sent to
+     * @param path    the path prefix for which this cookie can be sent
+     * @param expires the {@link Date} at which this cookie expires,
+     *                or <tt>null</tt> if the cookie expires at the end
+     *                of the session
+     * @param secure if true this cookie can only be sent over secure
+     * connections
+     * @throws IllegalArgumentException If cookie name is null or blank,
+     *   cookie name contains a blank, or cookie name starts with character $
+     *
+     */
+    public Cookie2(String domain, String name, String value,
+                   String path, Date expires, boolean secure) {
+        super(domain, name, value, path, expires, secure);
+    }
+
+    /**
+     * Creates a cookie with the given name, value, domain attribute,
+     * path attribute, expiration attribute, secure attribute, and ports
+     * attribute.
+     *
+     * @param name    the cookie name
+     * @param value   the cookie value
+     * @param domain  the domain this cookie can be sent to
+     * @param path    the path prefix for which this cookie can be sent
+     * @param expires the {@link Date} at which this cookie expires,
+     *                or <tt>null</tt> if the cookie expires at the end
+     *                of the session
+     * @param secure if true this cookie can only be sent over secure
+     * connections
+     * @param ports   the ports for which this cookie can be sent
+     * @throws IllegalArgumentException If cookie name is null or blank,
+     *   cookie name contains a blank, or cookie name starts with character $
+     *
+     */
+    public Cookie2(String domain, String name, String value,
+                   String path, Date expires, boolean secure, int[] ports) {
+        super(domain, name, value, path, expires, secure);
+        setPorts(ports);
+    }
+
+   /**
+     * If a user agent (web browser) presents this cookie to a user, the
+     * cookie's purpose will be described by the information at this URL.
+     *
+     * @see #setCommentURL(String)
+     */
+    public String getCommentURL() {
+        return cookieCommentURL;
+    }
+
+   /**
+     * If a user agent (web browser) presents this cookie to a user, the
+     * cookie's purpose will be described by the information at this URL.
+     *
+     * @param commentURL
+     *
+     * @see #getCommentURL()
+     */
+    public void setCommentURL(String commentURL) {
+        this.cookieCommentURL = commentURL;
+    }
+
+    /**
+     * Get the Port attribute. It restricts the ports to which a cookie
+     * may be returned in a Cookie request header.
+     *
+     * @see #setPorts(int[])
+     */
+    public int[] getPorts() {
+        return cookiePorts;
+    }
+
+   /**
+     * Set the Port attribute. It restricts the ports to which a cookie
+     * may be returned in a Cookie request header.
+     *
+     * @param ports
+     *
+     * @see #getPorts()
+     */
+    public void setPorts(int[] ports) {
+        this.cookiePorts = ports;
+    }
+
+    /**
+     * Set the Discard attribute.
+     *
+     * Note: <tt>Discard</tt> attribute overrides <tt>Max-age</tt>.
+     *
+     * @see #isPersistent()
+     */
+    public void setDiscard(boolean toDiscard) {
+        discard = toDiscard;
+    }
+
+    /**
+     * Returns <tt>false</tt> if the cookie should be discarded at the end
+     * of the "session"; <tt>true</tt> otherwise.
+     *
+     * @return <tt>false</tt> if the cookie should be discarded at the end
+     *         of the "session"; <tt>true</tt> otherwise
+     */
+    public boolean isPersistent() {
+        return (null != getExpiryDate()) && !discard;
+    }
+
+    /**
+     * Indicates whether the cookie had a domain attribute specified in the
+     * <tt>Set-Cookie2</tt> response header. This property
+     * has two uses:
+     * <ul>
+     * <li>This value is important for generating the <tt>Cookie</tt> request
header
+     * because the specification requires that the <tt>Cookie</tt> header
+     * should only include a domain attribute if the domain was specified in the
+     * <tt>Set-Cookie2</tt> header.
+     * </li>
+     * <li>This also ensures that if domain attribute appears more than once in
+     * the <tt>Set-Cookie2</tt> header, only the first appearance of domain
+     * attribute is used.
+     * </li>
+     * </ul>
+     * @param value <tt>true</tt> if the cookie's domain is specified
+     * in response header.
+     *
+     * @see #isDomainAttributeSpecified
+     */
+    public void setDomainAttributeSpecified(boolean value) {
+        hasDomainAttribute = value;
+    }
+
+    /**
+     * @return <tt>true</tt> if cookie domain attribute was specified in the
+     * <tt>Set-Cookie2</tt> header.
+     *
+     * @see #setDomainAttributeSpecified
+     */
+    public boolean isDomainAttributeSpecified() {
+        return hasDomainAttribute;
+    }
+
+    /**
+     * Indicates whether the cookie had a port attribute specified in the
+     * <tt>Set-Cookie2</tt> response header. This property
+     * has two uses:
+     * <ul>
+     * <li>This value is important for generating the <tt>Cookie</tt> request
header
+     * because the specification requires that the <tt>Cookie</tt> header
+     * should only include a port attribute if the port was specified in the
+     * <tt>Set-Cookie2</tt> header.
+     * </li>
+     * <li>This also ensures that if port attribute appears more than once in
+     * the <tt>Set-Cookie2</tt> header, only the first appearance of the port
+     * attribute is used.
+     * </li>
+     * </ul>
+     *
+     * @param value <tt>true</tt> if port attribute is specified in response
+     * header.
+     *
+     * @see #isPortAttributeSpecified
+     */
+    public void setPortAttributeSpecified(boolean value) {
+        hasPortAttribute = value;
+    }
+
+    /**
+     * @return <tt>true</tt> if cookie port attribute was specified in the
+     * <tt>Set-Cookie2</tt> header.
+     *
+     * @see #setPortAttributeSpecified
+     */
+    public boolean isPortAttributeSpecified() {
+        return hasPortAttribute;
+    }
+
+    /**
+     * Indicates whether the Port attribute in <tt>Set-Cookie2</tt> header
+     * contains no value (is of the form Port="").
+     * <p>
+     * This value is required for generating
+     * the <tt>Cookie</tt> request header because the specification requires
that if
+     * <tt>Set-Cookie2</tt> header contains a blank value for port attribute,
+     * the <tt>Cookie</tt> header should also contain a port attribute with no
value.
+     *
+     * @param value <tt>true</tt> if port attribute is specified as blank in
response
+     * header.
+     *
+     * @see #isPortAttributeBlank
+     */
+    public void setPortAttributeBlank(boolean value) {
+        isPortAttributeBlank = value;
+    }
+
+    /**
+     * @return <tt>true</tt> if the port attribute in <tt>Set-Cookie2</tt>
header
+     * had no value (was of the form Port="").
+     *
+     * @see #setPortAttributeBlank
+     */
+    public boolean isPortAttributeBlank() {
+        return isPortAttributeBlank;
+    }
+
+    /**
+     * Indicates whether the cookie had a version attribute specified in the
+     * <tt>Set-Cookie2</tt> response header. This property has two uses:
+     * <ul>
+     * <li>Only the first occurence of the version attribute in <tt>Set-Cookie2</tt>
+     * header is used, others ignored.</li>
+     * <li>Since version attribute is required for valid cookies, this property
+     * helps in checking this condition.</li>
+     * </ul>
+     *
+     * @param value <tt>true</tt> if version attribute is specified in response
+     * header.
+     * @see #isVersionAttributeSpecified()
+     */
+    public void setVersionAttributeSpecified(boolean value) {
+        hasVersionAttribute = value;
+    }
+
+    /**
+     * @return <tt>true</tt> if cookie version attribute was specified in the
+     * <tt>Set-Cookie2</tt> header.
+     *
+     * @see #setVersionAttributeSpecified
+     */
+    public boolean isVersionAttributeSpecified() {
+        return hasVersionAttribute;
+    }
+
+    /**
+     * Return a textual representation of the cookie.
+     *
+     * @return string.
+     */
+    public String toExternalForm() {
+        CookieSpec spec =
+                CookiePolicy.getCookieSpec(CookiePolicy.RFC_2965);
+        return spec.formatCookie(this);
+    }
+
+    /**
+     * Comment URL attribute
+     */
+    private String cookieCommentURL;
+
+    /**
+     * Port attribute.
+     */
+    private int[] cookiePorts;
+
+    /**
+     * Discard attribute.
+     */
+    private boolean discard = false;
+
+    /**
+     * Indicates if the set-cookie header included a Domain attribute for this
+     * cookie
+     */
+    private boolean hasDomainAttribute = false;
+
+    /**
+     * Indicates if the set-cookie2 header included a Port attribute for this
+     * cookie
+     */
+    private boolean hasPortAttribute = false;
+
+    /**
+     * Indicates if the set-cookie2 header's Port attribute did not have
+     * any value.
+     */
+    private boolean isPortAttributeBlank = false;
+
+    /**
+     * Indicates if the set-cookie2 header included a Version attribute
+     */
+    private boolean hasVersionAttribute = false;
+
+
+}
+

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

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

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

Added: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieAttributeHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieAttributeHandler.java?rev=264149&view=auto
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieAttributeHandler.java
(added)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieAttributeHandler.java
Mon Aug 29 07:28:21 2005
@@ -0,0 +1,57 @@
+package org.apache.commons.httpclient.cookie;
+
+import org.apache.commons.httpclient.Cookie;
+
+/**
+ * Ths interface represents a cookie attribute handler responsible
+ * for parsing, validating, matching and formatting a specific
+ * cookie attribute, such as path, domain, port, etc.
+ *
+ * Different cookie specifications can provide a specific
+ * implementation for this class based on their cookie handling
+ * rules.
+ *
+ * @author jain.samit@gmail.com (Samit Jain)
+ */
+public interface CookieAttributeHandler {
+
+  /**
+   * Parse the given cookie attribute value and update the corresponding
+   * {@link org.apache.commons.httpclient.Cookie} property.
+   *
+   * @param cookie {@link org.apache.commons.httpclient.Cookie} to be updated
+   * @param value cookie attribute value from the cookie response header
+   */
+  public void parse(Cookie cookie, String value)
+          throws MalformedCookieException;
+
+  /**
+   * Peforms cookie validation for the given attribute value.
+   *
+   * @param cookie {@link org.apache.commons.httpclient.Cookie} to validate
+   * @param value specific property of the host the cookie was received from.
+   * @throws MalformedCookieException if cookie validation fails for this attribute
+   */
+  public void validate(Cookie cookie, String value)
+          throws MalformedCookieException;
+
+  /**
+   * Matches the given value (property of the destination host where request is being
+   * submitted) with the corresponding cookie attribute.
+   *
+   * @param cookie {@link org.apache.commons.httpclient.Cookie} to match
+   * @param value specific property of the destination host
+   * @return <tt>true</tt> if the match is successful; <tt>false</tt>
otherwise
+   */
+  public boolean match(Cookie cookie, String value);
+
+  /**
+   * Format the cookie attribute suitable for sending in a cookie request header and
+   * append it to the given buffer.
+   *
+   * @param buffer the string buffer to use for output
+   * @param cookie {@link org.apache.commons.httpclient.Cookie} to get the attribute
+   *        from.
+   */
+  public void format(StringBuffer buffer, Cookie cookie);
+}

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

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

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

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=264149&r1=264148&r2=264149&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
Mon Aug 29 07:28:21 2005
@@ -320,4 +320,11 @@
     public static CookieSpec getCompatibilitySpec() {
         return getSpecByPolicy(COMPATIBILITY);
     }
+
+    public static int getCookieVersionBySpec(CookieSpec spec) {
+        if ((spec instanceof RFC2109Spec) ||
+            (spec instanceof RFC2965Spec))
+            return 1;
+        return 0;
+    }
 }

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java
Mon Aug 29 07:28:21 2005
@@ -74,7 +74,7 @@
     Cookie[] parse(String host, int port, String path, boolean secure,
       final String header)
       throws MalformedCookieException, IllegalArgumentException;
-
+         //TODO(jain): why is this method public
     /**
       * Parse the <tt>"Set-Cookie"</tt> Header into an array of Cookies.
       *
@@ -103,7 +103,7 @@
       */
     void parseAttribute(NameValuePair attribute, Cookie cookie)
       throws MalformedCookieException, IllegalArgumentException;
-
+         //TODO(jain): why is this method public
     /**
       * Validate the cookie according to validation rules defined by the 
       *  cookie specification.
@@ -223,12 +223,5 @@
      * @throws IllegalArgumentException if an input parameter is illegal
      */
     Header formatCookieHeader(Cookie cookie) throws IllegalArgumentException;
-
-    /**
-     * Gets the highest cookie version supported by this cookie specification.
-     *
-     * @return highest cookie version supported.
-     */
-    int getCookieVersion();
 
 }

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
Mon Aug 29 07:28:21 2005
@@ -204,8 +204,7 @@
 
     /**
       * Parse the <tt>"Set-Cookie"</tt> {@link Header} into an array of {@link
-      * Cookie}s. Subclasses that need to support other cookie headers can
-      * override this method.
+      * Cookie}s.
       *
       * <P>The syntax for the Set-Cookie response header is:
       *
@@ -245,24 +244,7 @@
         if (header == null) {
             throw new IllegalArgumentException("Header may not be null.");
         }
-
-        Cookie[] cookies;
-        // the default implementation only accepts Set-Cookie header
-        if (header.getName().equalsIgnoreCase(Header.SET_COOKIE_KEY)) {
-
-            cookies = parse(host, port, path, secure, header.getValue());
-            // set header name of cookies so we can identify later whether cookie
-            // came from set-cookie header
-            for (int i = 0; i < cookies.length; i++) {
-                cookies[i].setHeaderName(Header.SET_COOKIE_KEY);
-            }
-        }
-        else {
-            throw new MalformedCookieException("Header name is not valid. " +
-                                               "Default implementation supports " +
-                                               "only \"set-cookie\" header.");
-        }
-        return cookies;
+        return parse(host, port, path, secure, header.getValue());
     }
 
 
@@ -358,15 +340,15 @@
     }
 
     
-    public Collection getValidDateFormats() {
-        return this.datepatterns;
-    }
-
-    public void setValidDateFormats(final Collection datepatterns) {
-        this.datepatterns = datepatterns;
-    }
+	public Collection getValidDateFormats() {
+		return this.datepatterns;
+	}
+
+	public void setValidDateFormats(final Collection datepatterns) {
+		this.datepatterns = datepatterns;
+	}
 
-    /**
+	/**
       * Performs most common {@link Cookie} validation
       *
       * @param host the host from which the {@link Cookie} was received
@@ -590,7 +572,7 @@
      */
     private static void addInPathOrder(List list, Cookie addCookie) {
         int i = 0;
-        // TODO (jain): better implementation of sorting cookies
+
         for (i = 0; i < list.size(); i++) {
             Cookie c = (Cookie) list.get(i);
             if (addCookie.compare(addCookie, c) > 0) {
@@ -671,11 +653,6 @@
     public Header formatCookieHeader(Cookie cookie) {
         LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie)");
         return new Header("Cookie", formatCookie(cookie));
-    }
-
-    public int getCookieVersion() {
-        // default cookie version is 0
-        return 0;
     }
 
 }

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java
Mon Aug 29 07:28:21 2005
@@ -149,8 +149,4 @@
         return false;
     }
 
-    public int getCookieVersion() {
-        return -1;
-    }
-
 }

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java?rev=264149&r1=264148&r2=264149&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
Mon Aug 29 07:28:21 2005
@@ -53,8 +53,14 @@
 public class RFC2109Spec extends CookieSpecBase {
 
     private final ParameterFormatter formatter;
-    
-    /** Default constructor */    
+
+    /**
+     * Cookie Response Header  name for cookies processed
+     * by this spec.
+     */
+    public static String SET_COOKIE_KEY = "set-cookie";
+
+    /** Default constructor */
     public RFC2109Spec() {
         super();
         this.formatter = new ParameterFormatter();



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message