Browse Source

added httpOnly argument to Web.setCookie (fixed issue #1407)

Simon Krajewski 12 years ago
parent
commit
09bafc8e74
2 changed files with 5 additions and 8 deletions
  1. 2 1
      std/neko/Web.hx
  2. 3 7
      std/php/Web.hx

+ 2 - 1
std/neko/Web.hx

@@ -180,13 +180,14 @@ 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( key : String, value : String, ?expire: Date, ?domain: String, ?path: String, ?secure: Bool ) {
+	public static function setCookie( key : String, value : String, ?expire: Date, ?domain: String, ?path: String, ?secure: Bool, ?httpOnly: Bool ) {
 		var buf = new StringBuf();
 		var buf = new StringBuf();
 		buf.add(value);
 		buf.add(value);
 		if( expire != null ) addPair(buf, "expires=", DateTools.format(expire, "%a, %d-%b-%Y %H:%M:%S GMT"));
 		if( expire != null ) addPair(buf, "expires=", DateTools.format(expire, "%a, %d-%b-%Y %H:%M:%S GMT"));
 		addPair(buf, "domain=", domain);
 		addPair(buf, "domain=", domain);
 		addPair(buf, "path=", path);
 		addPair(buf, "path=", path);
 		if( secure ) addPair(buf, "secure", "");
 		if( secure ) addPair(buf, "secure", "");
+		if( httpOnly ) addPair(buf, "HttpOnly", "");
 		var v = buf.toString();
 		var v = buf.toString();
 		_set_cookie(untyped key.__s, untyped v.__s);
 		_set_cookie(untyped key.__s, untyped v.__s);
 	}
 	}

+ 3 - 7
std/php/Web.hx

@@ -260,17 +260,13 @@ 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( key : String, value : String, ?expire: Date, ?domain: String, ?path: String, ?secure: Bool ) {
+	public static function setCookie( key : String, value : String, ?expire: Date, ?domain: String, ?path: String, ?secure: Bool, ?httpOnly: Bool ) {
 		var t = expire == null ? 0 : Std.int(expire.getTime()/1000.0);
 		var t = expire == null ? 0 : Std.int(expire.getTime()/1000.0);
 		if(path == null) path = '/';
 		if(path == null) path = '/';
 		if(domain == null) domain = '';
 		if(domain == null) domain = '';
 		if(secure == null) secure = false;
 		if(secure == null) secure = false;
-		untyped __call__("setcookie", key, value, t, path, domain, secure);
-	}
-
-	static function addPair( name, value ) : String {
-		if( value == null ) return "";
-		return "; " + name + value;
+		if(httpOnly == null) httpOnly = false;
+		untyped __call__("setcookie", key, value, t, path, domain, secure, httpOnly);
 	}
 	}
 
 
 	/**
 	/**