1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.client5.http.impl.cookie;
29
30 import java.io.Serializable;
31 import java.util.Date;
32 import java.util.HashMap;
33 import java.util.Locale;
34 import java.util.Map;
35
36 import org.apache.hc.client5.http.cookie.SetCookie;
37 import org.apache.hc.core5.util.Args;
38
39
40
41
42
43
44 public final class BasicClientCookie implements SetCookie, Cloneable, Serializable {
45
46 private static final long serialVersionUID = -3869795591041535538L;
47
48
49
50
51
52
53
54 public BasicClientCookie(final String name, final String value) {
55 super();
56 Args.notNull(name, "Name");
57 this.name = name;
58 this.attribs = new HashMap<>();
59 this.value = value;
60 }
61
62
63
64
65
66
67 @Override
68 public String getName() {
69 return this.name;
70 }
71
72
73
74
75
76
77 @Override
78 public String getValue() {
79 return this.value;
80 }
81
82
83
84
85
86
87 @Override
88 public void setValue(final String value) {
89 this.value = value;
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103 @Override
104 public Date getExpiryDate() {
105 return cookieExpiryDate;
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119 @Override
120 public void setExpiryDate (final Date expiryDate) {
121 cookieExpiryDate = expiryDate;
122 }
123
124
125
126
127
128
129
130
131
132 @Override
133 public boolean isPersistent() {
134 return (null != cookieExpiryDate);
135 }
136
137
138
139
140
141
142
143
144
145 @Override
146 public String getDomain() {
147 return cookieDomain;
148 }
149
150
151
152
153
154
155
156
157 @Override
158 public void setDomain(final String domain) {
159 if (domain != null) {
160 cookieDomain = domain.toLowerCase(Locale.ROOT);
161 } else {
162 cookieDomain = null;
163 }
164 }
165
166
167
168
169
170
171
172
173
174 @Override
175 public String getPath() {
176 return cookiePath;
177 }
178
179
180
181
182
183
184
185
186
187 @Override
188 public void setPath(final String path) {
189 cookiePath = path;
190 }
191
192
193
194
195
196 @Override
197 public boolean isSecure() {
198 return isSecure;
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213 @Override
214 public void setSecure (final boolean secure) {
215 isSecure = secure;
216 }
217
218
219
220
221
222
223
224 @Override
225 public boolean isExpired(final Date date) {
226 Args.notNull(date, "Date");
227 return (cookieExpiryDate != null
228 && cookieExpiryDate.getTime() <= date.getTime());
229 }
230
231
232
233
234 @Override
235 public Date getCreationDate() {
236 return creationDate;
237 }
238
239
240
241
242 public void setCreationDate(final Date creationDate) {
243 this.creationDate = creationDate;
244 }
245
246 public void setAttribute(final String name, final String value) {
247 this.attribs.put(name, value);
248 }
249
250 @Override
251 public String getAttribute(final String name) {
252 return this.attribs.get(name);
253 }
254
255 @Override
256 public boolean containsAttribute(final String name) {
257 return this.attribs.containsKey(name);
258 }
259
260
261
262
263 public boolean removeAttribute(final String name) {
264 return this.attribs.remove(name) != null;
265 }
266
267 @Override
268 public Object clone() throws CloneNotSupportedException {
269 final BasicClientCookie./../../../org/apache/hc/client5/http/impl/cookie/BasicClientCookie.html#BasicClientCookie">BasicClientCookie clone = (BasicClientCookie) super.clone();
270 clone.attribs = new HashMap<>(this.attribs);
271 return clone;
272 }
273
274 @Override
275 public String toString() {
276 final StringBuilder buffer = new StringBuilder();
277 buffer.append("[name: ");
278 buffer.append(this.name);
279 buffer.append("; ");
280 buffer.append("value: ");
281 buffer.append(this.value);
282 buffer.append("; ");
283 buffer.append("domain: ");
284 buffer.append(this.cookieDomain);
285 buffer.append("; ");
286 buffer.append("path: ");
287 buffer.append(this.cookiePath);
288 buffer.append("; ");
289 buffer.append("expiry: ");
290 buffer.append(this.cookieExpiryDate);
291 buffer.append("]");
292 return buffer.toString();
293 }
294
295
296
297
298 private final String name;
299
300
301 private Map<String, String> attribs;
302
303
304 private String value;
305
306
307 private String cookieDomain;
308
309
310 private Date cookieExpiryDate;
311
312
313 private String cookiePath;
314
315
316 private boolean isSecure;
317
318 private Date creationDate;
319
320 }
321