1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http;
20
21 import java.util.concurrent.TimeUnit;
22
23 public class HttpCookie
24 {
25 private final String _name;
26 private final String _value;
27 private final String _comment;
28 private final String _domain;
29 private final long _maxAge;
30 private final String _path;
31 private final boolean _secure;
32 private final int _version;
33 private final boolean _httpOnly;
34 private final long _expiration;
35
36 public HttpCookie(String name, String value)
37 {
38 this(name, value, -1);
39 }
40
41 public HttpCookie(String name, String value, String domain, String path)
42 {
43 this(name, value, domain, path, -1, false, false);
44 }
45
46 public HttpCookie(String name, String value, long maxAge)
47 {
48 this(name, value, null, null, maxAge, false, false);
49 }
50
51 public HttpCookie(String name, String value, String domain, String path, long maxAge, boolean httpOnly, boolean secure)
52 {
53 this(name, value, domain, path, maxAge, httpOnly, secure, null, 0);
54 }
55
56 public HttpCookie(String name, String value, String domain, String path, long maxAge, boolean httpOnly, boolean secure, String comment, int version)
57 {
58 _name = name;
59 _value = value;
60 _domain = domain;
61 _path = path;
62 _maxAge = maxAge;
63 _httpOnly = httpOnly;
64 _secure = secure;
65 _comment = comment;
66 _version = version;
67 _expiration = maxAge < 0 ? -1 : System.nanoTime() + TimeUnit.SECONDS.toNanos(maxAge);
68 }
69
70
71
72
73 public String getName()
74 {
75 return _name;
76 }
77
78
79
80
81 public String getValue()
82 {
83 return _value;
84 }
85
86
87
88
89 public String getComment()
90 {
91 return _comment;
92 }
93
94
95
96
97 public String getDomain()
98 {
99 return _domain;
100 }
101
102
103
104
105 public long getMaxAge()
106 {
107 return _maxAge;
108 }
109
110
111
112
113 public String getPath()
114 {
115 return _path;
116 }
117
118
119
120
121 public boolean isSecure()
122 {
123 return _secure;
124 }
125
126
127
128
129 public int getVersion()
130 {
131 return _version;
132 }
133
134
135
136
137 public boolean isHttpOnly()
138 {
139 return _httpOnly;
140 }
141
142
143
144
145
146 public boolean isExpired(long timeNanos)
147 {
148 return _expiration >= 0 && timeNanos >= _expiration;
149 }
150
151
152
153
154 public String asString()
155 {
156 StringBuilder builder = new StringBuilder();
157 builder.append(getName()).append("=").append(getValue());
158 if (getDomain() != null)
159 builder.append(";$Domain=").append(getDomain());
160 if (getPath() != null)
161 builder.append(";$Path=").append(getPath());
162 return builder.toString();
163 }
164 }