001/*
002 * ====================================================================
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 * ====================================================================
020 *
021 * This software consists of voluntary contributions made by many
022 * individuals on behalf of the Apache Software Foundation.  For more
023 * information on the Apache Software Foundation, please see
024 * <http://www.apache.org/>.
025 *
026 */
027
028package org.apache.http.cookie;
029
030import java.util.Date;
031
032import org.apache.http.annotation.Obsolete;
033
034/**
035 * Cookie interface represents a token or short packet of state information
036 * (also referred to as "magic-cookie") that the HTTP agent and the target
037 * server can exchange to maintain a session. In its simples form an HTTP
038 * cookie is merely a name / value pair.
039 * <p>
040 * Please do not use attributes marked as @Obsolete. They have been rendered
041 * obsolete by RFC 6265.
042 *
043 * @since 4.0
044 */
045public interface Cookie {
046
047    /**
048     * Returns the name.
049     *
050     * @return String name The name
051     */
052    String getName();
053
054    /**
055     * Returns the value.
056     *
057     * @return String value The current value.
058     */
059    String getValue();
060
061    /**
062     * Returns the comment describing the purpose of this cookie, or
063     * {@code null} if no such comment has been defined.
064     *
065     * @return comment
066     */
067    @Obsolete
068    String getComment();
069
070    /**
071     * If a user agent (web browser) presents this cookie to a user, the
072     * cookie's purpose will be described by the information at this URL.
073     */
074    @Obsolete
075    String getCommentURL();
076
077    /**
078     * Returns the expiration {@link Date} of the cookie, or {@code null}
079     * if none exists.
080     * <p><strong>Note:</strong> the object returned by this method is
081     * considered immutable. Changing it (e.g. using setTime()) could result
082     * in undefined behaviour. Do so at your peril. </p>
083     * @return Expiration {@link Date}, or {@code null}.
084     */
085    Date getExpiryDate();
086
087    /**
088     * Returns {@code false} if the cookie should be discarded at the end
089     * of the "session"; {@code true} otherwise.
090     *
091     * @return {@code false} if the cookie should be discarded at the end
092     *         of the "session"; {@code true} otherwise
093     */
094    boolean isPersistent();
095
096    /**
097     * Returns domain attribute of the cookie. The value of the Domain
098     * attribute specifies the domain for which the cookie is valid.
099     *
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