View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.cookie;
29  
30  import java.util.Date;
31  
32  import org.apache.http.annotation.Obsolete;
33  
34  /**
35   * Cookie interface represents a token or short packet of state information
36   * (also referred to as "magic-cookie") that the HTTP agent and the target
37   * server can exchange to maintain a session. In its simples form an HTTP
38   * cookie is merely a name / value pair.
39   * <p>
40   * Please do not use attributes marked as @Obsolete. They have been rendered
41   * obsolete by RFC 6265.
42   *
43   * @since 4.0
44   */
45  public interface Cookie {
46  
47      /**
48       * Returns the name.
49       *
50       * @return String name The name
51       */
52      String getName();
53  
54      /**
55       * Returns the value.
56       *
57       * @return String value The current value.
58       */
59      String getValue();
60  
61      /**
62       * Returns the comment describing the purpose of this cookie, or
63       * {@code null} if no such comment has been defined.
64       *
65       * @return comment
66       */
67      @Obsolete
68      String getComment();
69  
70      /**
71       * If a user agent (web browser) presents this cookie to a user, the
72       * cookie's purpose will be described by the information at this URL.
73       */
74      @Obsolete
75      String getCommentURL();
76  
77      /**
78       * Returns the expiration {@link Date} of the cookie, or {@code null}
79       * if none exists.
80       * <p><strong>Note:</strong> the object returned by this method is
81       * considered immutable. Changing it (e.g. using setTime()) could result
82       * in undefined behaviour. Do so at your peril. </p>
83       * @return Expiration {@link Date}, or {@code null}.
84       */
85      Date getExpiryDate();
86  
87      /**
88       * Returns {@code false} if the cookie should be discarded at the end
89       * of the "session"; {@code true} otherwise.
90       *
91       * @return {@code false} if the cookie should be discarded at the end
92       *         of the "session"; {@code true} otherwise
93       */
94      boolean isPersistent();
95  
96      /**
97       * Returns domain attribute of the cookie. The value of the Domain
98       * attribute specifies the domain for which the cookie is valid.
99       *
100      * @return the value of the domain attribute.
101      */
102     String getDomain();
103 
104     /**
105      * Returns the path attribute of the cookie. The value of the Path
106      * attribute specifies the subset of URLs on the origin server to which
107      * this cookie applies.
108      *
109      * @return The value of the path attribute.
110      */
111     String getPath();
112 
113     /**
114      * Get the Port attribute. It restricts the ports to which a cookie
115      * may be returned in a Cookie request header.
116      */
117     @Obsolete
118     int[] getPorts();
119 
120     /**
121      * Indicates whether this cookie requires a secure connection.
122      *
123      * @return  {@code true} if this cookie should only be sent
124      *          over secure connections, {@code false} otherwise.
125      */
126     boolean isSecure();
127 
128     /**
129      * Returns the version of the cookie specification to which this
130      * cookie conforms.
131      *
132      * @return the version of the cookie.
133      */
134     @Obsolete
135     int getVersion();
136 
137     /**
138      * Returns true if this cookie has expired.
139      * @param date Current time
140      *
141      * @return {@code true} if the cookie has expired.
142      */
143     boolean isExpired(final Date date);
144 
145     //TODO: RFC 6265 requires cookies to track their creation time; add #getCreationDate()
146 
147 }
148