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 org.jboss.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 * Returns the name of this {@link Cookie}.
26 *
27 * @return The name of this {@link Cookie}
28 */
29 String name();
30
31 /**
32 * Returns the value of this {@link Cookie}.
33 *
34 * @return The value of this {@link Cookie}
35 */
36 String value();
37
38 /**
39 * Sets the value of this {@link Cookie}.
40 *
41 * @param value The value to set
42 */
43 void setValue(String value);
44
45 /**
46 * Returns true if the raw value of this {@link Cookie},
47 * was wrapped with double quotes in original Set-Cookie header.
48 *
49 * @return If the value of this {@link Cookie} is to be wrapped
50 */
51 boolean wrap();
52
53 /**
54 * Sets true if the value of this {@link Cookie}
55 * is to be wrapped with double quotes.
56 *
57 * @param wrap true if wrap
58 */
59 void setWrap(boolean wrap);
60
61 /**
62 * Returns the domain of this {@link Cookie}.
63 *
64 * @return The domain of this {@link Cookie}
65 */
66 String domain();
67
68 /**
69 * Sets the domain of this {@link Cookie}.
70 *
71 * @param domain The domain to use
72 */
73 void setDomain(String domain);
74
75 /**
76 * Returns the path of this {@link Cookie}.
77 *
78 * @return The {@link Cookie}'s path
79 */
80 String path();
81
82 /**
83 * Sets the path of this {@link Cookie}.
84 *
85 * @param path The path to use for this {@link Cookie}
86 */
87 void setPath(String path);
88
89 /**
90 * Returns the maximum age of this {@link Cookie} in seconds or {@link Integer#MIN_VALUE} if unspecified
91 *
92 * @return The maximum age of this {@link Cookie}
93 */
94 int maxAge();
95
96 /**
97 * Sets the maximum age of this {@link Cookie} in seconds.
98 * If an age of {@code 0} is specified, this {@link Cookie} will be
99 * automatically removed by browser because it will expire immediately.
100 * If {@link Integer#MIN_VALUE} is specified, this {@link Cookie} will be removed when the
101 * browser is closed.
102 *
103 * @param maxAge The maximum age of this {@link Cookie} in seconds
104 */
105 void setMaxAge(int maxAge);
106
107 /**
108 * Checks to see if this {@link Cookie} is secure
109 *
110 * @return True if this {@link Cookie} is secure, otherwise false
111 */
112 boolean isSecure();
113
114 /**
115 * Sets the security getStatus of this {@link Cookie}
116 *
117 * @param secure True if this {@link Cookie} is to be secure, otherwise false
118 */
119 void setSecure(boolean secure);
120
121 /**
122 * Checks to see if this {@link Cookie} can only be accessed via HTTP.
123 * If this returns true, the {@link Cookie} cannot be accessed through
124 * client side script - But only if the browser supports it.
125 * For more information, please look <a href="http://www.owasp.org/index.php/HTTPOnly">here</a>
126 *
127 * @return True if this {@link Cookie} is HTTP-only or false if it isn't
128 */
129 boolean isHttpOnly();
130
131 /**
132 * Determines if this {@link Cookie} is HTTP only.
133 * If set to true, this {@link Cookie} cannot be accessed by a client
134 * side script. However, this works only if the browser supports it.
135 * For for information, please look
136 * <a href="http://www.owasp.org/index.php/HTTPOnly">here</a>.
137 *
138 * @param httpOnly True if the {@link Cookie} is HTTP only, otherwise false.
139 */
140 void setHttpOnly(boolean httpOnly);
141 }