@@ -26,9 +26,10 @@ public class Cookie {
26
26
private final String domain ;
27
27
private final Date expiry ;
28
28
private final boolean isSecure ;
29
+ private final boolean isHttpOnly ;
29
30
30
31
/**
31
- * Creates an insecure cookie with no domain specified.
32
+ * Creates an insecure non-httpOnly cookie with no domain specified.
32
33
*
33
34
* @param name The name of the cookie; may not be null or an empty string.
34
35
* @param value The cookie value; may not be null.
@@ -42,7 +43,7 @@ public Cookie(String name, String value, String path, Date expiry) {
42
43
}
43
44
44
45
/**
45
- * Creates an insecure cookie.
46
+ * Creates an insecure non-httpOnly cookie.
46
47
*
47
48
* @param name The name of the cookie; may not be null or an empty string.
48
49
* @param value The cookie value; may not be null.
@@ -57,7 +58,7 @@ public Cookie(String name, String value, String domain, String path, Date expiry
57
58
}
58
59
59
60
/**
60
- * Creates a cookie.
61
+ * Creates a non-httpOnly cookie.
61
62
*
62
63
* @param name The name of the cookie; may not be null or an empty string.
63
64
* @param value The cookie value; may not be null.
@@ -68,13 +69,31 @@ public Cookie(String name, String value, String domain, String path, Date expiry
68
69
* @param isSecure Whether this cookie requires a secure connection.
69
70
*/
70
71
public Cookie (String name , String value , String domain , String path , Date expiry ,
71
- boolean isSecure ) {
72
+ boolean isSecure ) {
73
+ this (name , value , domain , path , expiry , isSecure , false );
74
+ }
75
+
76
+ /**
77
+ * Creates a cookie.
78
+ *
79
+ * @param name The name of the cookie; may not be null or an empty string.
80
+ * @param value The cookie value; may not be null.
81
+ * @param domain The domain the cookie is visible to.
82
+ * @param path The path the cookie is visible to. If left blank or set to null, will be set to
83
+ * "/".
84
+ * @param expiry The cookie's expiration date; may be null.
85
+ * @param isSecure Whether this cookie requires a secure connection.
86
+ * @param isHttpOnly Whether this cookie is a httpOnly cooke.
87
+ */
88
+ public Cookie (String name , String value , String domain , String path , Date expiry ,
89
+ boolean isSecure , boolean isHttpOnly ) {
72
90
this .name = name ;
73
91
this .value = value ;
74
92
this .path = path == null || "" .equals (path ) ? "/" : path ;
75
93
76
94
this .domain = stripPort (domain );
77
95
this .isSecure = isSecure ;
96
+ this .isHttpOnly = isHttpOnly ;
78
97
79
98
if (expiry != null ) {
80
99
// Expiration date is specified in seconds since (UTC) epoch time, so truncate the date.
@@ -125,6 +144,10 @@ public boolean isSecure() {
125
144
return isSecure ;
126
145
}
127
146
147
+ public boolean isHttpOnly () {
148
+ return isHttpOnly ;
149
+ }
150
+
128
151
public Date getExpiry () {
129
152
return expiry ;
130
153
}
@@ -193,6 +216,7 @@ public static class Builder {
193
216
private String domain ;
194
217
private Date expiry ;
195
218
private boolean secure ;
219
+ private boolean httpOnly ;
196
220
197
221
public Builder (String name , String value ) {
198
222
this .name = name ;
@@ -219,8 +243,13 @@ public Builder isSecure(boolean secure) {
219
243
return this ;
220
244
}
221
245
246
+ public Builder isHttpOnly (boolean httpOnly ) {
247
+ this .httpOnly = httpOnly ;
248
+ return this ;
249
+ }
250
+
222
251
public Cookie build () {
223
- return new Cookie (name , value , domain , path , expiry , secure );
252
+ return new Cookie (name , value , domain , path , expiry , secure , httpOnly );
224
253
}
225
254
}
226
255
}
0 commit comments