View Javadoc

1   /*
2    * Copyright 2015 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http.cookie;
17  
18  /**
19   * An interface defining an
20   * <a href="http://en.wikipedia.org/wiki/HTTP_cookie">HTTP cookie</a>.
21   */
22  public interface Cookie extends Comparable<Cookie> {
23  
24      /**
25       * Constant for undefined MaxAge attribute value.
26       */
27      long UNDEFINED_MAX_AGE = Long.MIN_VALUE;
28  
29      /**
30       * Returns the name of this {@link Cookie}.
31       *
32       * @return The name of this {@link Cookie}
33       */
34      String name();
35  
36      /**
37       * Returns the value of this {@link Cookie}.
38       *
39       * @return The value of this {@link Cookie}
40       */
41      String value();
42  
43      /**
44       * Sets the value of this {@link Cookie}.
45       *
46       * @param value The value to set
47       */
48      void setValue(String value);
49  
50      /**
51       * Returns true if the raw value of this {@link Cookie},
52       * was wrapped with double quotes in original Set-Cookie header.
53       *
54       * @return If the value of this {@link Cookie} is to be wrapped
55       */
56      boolean wrap();
57  
58      /**
59       * Sets true if the value of this {@link Cookie}
60       * is to be wrapped with double quotes.
61       *
62       * @param wrap true if wrap
63       */
64      void setWrap(boolean wrap);
65  
66      /**
67       * Returns the domain of this {@link Cookie}.
68       *
69       * @return The domain of this {@link Cookie}
70       */
71      String domain();
72  
73      /**
74       * Sets the domain of this {@link Cookie}.
75       *
76       * @param domain The domain to use
77       */
78      void setDomain(String domain);
79  
80      /**
81       * Returns the path of this {@link Cookie}.
82       *
83       * @return The {@link Cookie}'s path
84       */
85      String path();
86  
87      /**
88       * Sets the path of this {@link Cookie}.
89       *
90       * @param path The path to use for this {@link Cookie}
91       */
92      void setPath(String path);
93  
94      /**
95       * Returns the maximum age of this {@link Cookie} in seconds or {@link Cookie#UNDEFINED_MAX_AGE} if unspecified
96       *
97       * @return The maximum age of this {@link Cookie}
98       */
99      long maxAge();
100 
101     /**
102      * Sets the maximum age of this {@link Cookie} in seconds.
103      * If an age of {@code 0} is specified, this {@link Cookie} will be
104      * automatically removed by browser because it will expire immediately.
105      * If {@link Cookie#UNDEFINED_MAX_AGE} is specified, this {@link Cookie} will be removed when the
106      * browser is closed.
107      *
108      * @param maxAge The maximum age of this {@link Cookie} in seconds
109      */
110     void setMaxAge(long maxAge);
111 
112     /**
113      * Checks to see if this {@link Cookie} is secure
114      *
115      * @return True if this {@link Cookie} is secure, otherwise false
116      */
117     boolean isSecure();
118 
119     /**
120      * Sets the security getStatus of this {@link Cookie}
121      *
122      * @param secure True if this {@link Cookie} is to be secure, otherwise false
123      */
124     void setSecure(boolean secure);
125 
126     /**
127      * Checks to see if this {@link Cookie} can only be accessed via HTTP.
128      * If this returns true, the {@link Cookie} cannot be accessed through
129      * client side script - But only if the browser supports it.
130      * For more information, please look <a href="http://www.owasp.org/index.php/HTTPOnly">here</a>
131      *
132      * @return True if this {@link Cookie} is HTTP-only or false if it isn't
133      */
134     boolean isHttpOnly();
135 
136     /**
137      * Determines if this {@link Cookie} is HTTP only.
138      * If set to true, this {@link Cookie} cannot be accessed by a client
139      * side script. However, this works only if the browser supports it.
140      * For for information, please look
141      * <a href="http://www.owasp.org/index.php/HTTPOnly">here</a>.
142      *
143      * @param httpOnly True if the {@link Cookie} is HTTP only, otherwise false.
144      */
145     void setHttpOnly(boolean httpOnly);
146 }