@@ -92,6 +92,7 @@ public class Cookie implements Cloneable, Serializable {
92
92
private boolean secure ; // ;Secure ... e.g. use SSL
93
93
private int version = 0 ; // ;Version=1 ... means RFC 2109++ style
94
94
private boolean isHttpOnly = false ;
95
+ private SameSite sameSite ;
95
96
96
97
/**
97
98
* Constructs a cookie with the specified name and value.
@@ -422,4 +423,59 @@ public void setHttpOnly(boolean isHttpOnly) {
422
423
public boolean isHttpOnly () {
423
424
return isHttpOnly ;
424
425
}
426
+
427
+ /**
428
+ * Returns the <i>SameSite</i> attribute of the cookie.
429
+ *
430
+ * @return the <i>SameSite</i> attribute of the cookie
431
+ */
432
+ public SameSite getSameSite () {
433
+ return sameSite ;
434
+ }
435
+
436
+ /**
437
+ * Sets the <i>SameSite</i> attribute of the cookie.
438
+ *
439
+ * @param sameSite the <i>SameSite</i> attribute of the cookie
440
+ */
441
+ public void setSameSite (SameSite sameSite ) {
442
+ this .sameSite = sameSite ;
443
+ }
444
+
445
+ /**
446
+ * Available SameSite directives for the cookie as described in RFC6265bis.
447
+ */
448
+ public enum SameSite {
449
+
450
+ /**
451
+ * The cookie will only be sent if the site for the cookie matches the current
452
+ * site URL. The cookie will not be sent along with requests initiated by
453
+ * third party websites.
454
+ */
455
+ STRICT ("Strict" ),
456
+
457
+ /**
458
+ * The cookie will only be sent if the site for the cookie matches the current
459
+ * site URL. The cookie will be sent along with the GET request initiated by
460
+ * third party website.
461
+ */
462
+ LAX ("Lax" ),
463
+
464
+ /**
465
+ * The cookie will be sent cross-origin. This directive requires the Secure
466
+ * attribute.
467
+ */
468
+ NONE ("None" );
469
+
470
+ private final String value ;
471
+
472
+ SameSite (final String value ) {
473
+ this .value = value ;
474
+ }
475
+
476
+ @ Override
477
+ public String toString () {
478
+ return this .value ;
479
+ }
480
+ }
425
481
}
0 commit comments