Kaynağa Gözat

allows setting secure and sameSite attributes in js.Cookie (#10317)

Poga Po 3 yıl önce
ebeveyn
işleme
16891c2b70
1 değiştirilmiş dosya ile 7 ekleme ve 1 silme
  1. 7 1
      std/js/Cookie.hx

+ 7 - 1
std/js/Cookie.hx

@@ -29,7 +29,7 @@ class Cookie {
 		Create or update a cookie.
 		@param  expireDelay  In seconds. If null, the cookie expires at end of session.
 	**/
-	public static function set(name:String, value:String, ?expireDelay:Int, ?path:String, ?domain:String) {
+	public static function set(name:String, value:String, ?expireDelay:Int, ?path:String, ?domain:String, ?secure:Bool, ?sameSite:String) {
 		var s = name + "=" + StringTools.urlEncode(value);
 		if (expireDelay != null) {
 			var d = DateTools.delta(Date.now(), expireDelay * 1000);
@@ -41,6 +41,12 @@ class Cookie {
 		if (domain != null) {
 			s += ";domain=" + domain;
 		}
+		if (secure == true) {
+			s += ";secure";
+		}
+		if (sameSite != null) {
+			s += ";SameSite=" + sameSite;
+		}
 		Browser.document.cookie = s;
 	}