Ver código fonte

setCookie additional params

Nicolas Cannasse 17 anos atrás
pai
commit
2c63385b90
2 arquivos alterados com 17 adições e 2 exclusões
  1. 1 0
      doc/CHANGES.txt
  2. 16 2
      std/neko/Web.hx

+ 1 - 0
doc/CHANGES.txt

@@ -21,6 +21,7 @@
 	optimized for loops (Array and IntIter)
 	optimized for loops (Array and IntIter)
 	added #line support
 	added #line support
 	more f9 Null<T> support for "if" and array declarations
 	more f9 Null<T> support for "if" and array declarations
+	more neko.Web.setCookie parameters
 
 
 2007-10-31: 1.16
 2007-10-31: 1.16
 	use _sans font for default flash traces (better Linux support)
 	use _sans font for default flash traces (better Linux support)

+ 16 - 2
std/neko/Web.hx

@@ -182,8 +182,22 @@ class Web {
 	/**
 	/**
 		Set a Cookie value in the HTTP headers. Same remark as setHeader.
 		Set a Cookie value in the HTTP headers. Same remark as setHeader.
 	**/
 	**/
-	public static function setCookie( k : String, v : String ) {
-		_set_cookie(untyped k.__s,untyped v.__s);
+	public static function setCookie( key : String, value : String, ?expire: Date, ?domain: String, ?path: String, ?secure: Bool ) {
+		var buf = new StringBuf();
+		buf.add(value);
+		addPair(buf, "expires=", DateTools.format(expire, "%a, %d-%b-%Y %H:%M:%S GMT"));
+		addPair(buf, "domain=", domain);
+		addPair(buf, "path=", path);
+		if( secure ) addPair(buf, "secure", "");
+		var v = buf.toString();
+		_set_cookie(untyped key.__s, untyped v.__s);
+	}
+
+	static function addPair( buf : StringBuf, name, value ) {
+		if( value == null ) return;
+		buf.add("; ");
+		buf.add(name);
+		buf.add(value);
 	}
 	}
 
 
 	/**
 	/**