From f456719f4a3c4af83f92a54489263882499dbd87 Mon Sep 17 00:00:00 2001 From: lublak Date: Wed, 25 Dec 2019 14:29:09 +0100 Subject: [PATCH 1/2] Add addHeader function for neko and php based on https://github.com/HaxeFoundation/neko/issues/204 --- std/neko/Web.hx | 11 +++++++++++ std/php/Web.hx | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/std/neko/Web.hx b/std/neko/Web.hx index 5623895b32e..adc79ef08a6 100644 --- a/std/neko/Web.hx +++ b/std/neko/Web.hx @@ -109,6 +109,14 @@ class Web { _cgi_set_header(untyped h.__s, untyped v.__s); } + /** + Add an output header value. If some data have been printed, the headers have + already been sent so this will raise an exception. + **/ + public static function setHeader(h:String, v:String) { + _cgi_add_header(untyped h.__s, untyped v.__s); + } + /** Set the HTTP return code. Same remark as setHeader. **/ @@ -309,6 +317,7 @@ class Web { static var _get_uri:Dynamic; static var _cgi_redirect:Dynamic; static var _cgi_set_header:Dynamic; + static var _cgi_add_header:Dynamic; static var _set_return_code:Dynamic; static var _get_client_header:Dynamic; static var _get_params_string:Dynamic; @@ -336,6 +345,7 @@ class Web { _get_uri = Lib.load(lib, "get_uri", 0); _cgi_redirect = Lib.load(lib, "redirect", 1); _cgi_set_header = Lib.load(lib, "set_header", 2); + _cgi_add_header = Lib.load(lib, "add_header", 2); _set_return_code = Lib.load(lib, "set_return_code", 1); _get_client_header = Lib.load(lib, "get_client_header", 1); _get_params_string = Lib.load(lib, "get_params_string", 0); @@ -368,6 +378,7 @@ class Web { Lib.print("Location: " + v + "\n"); }; _cgi_set_header = function(h, v) {}; + _cgi_add_header = function(h, v) {}; _set_return_code = function(i) {}; _get_client_header = function(h) { return null; diff --git a/std/php/Web.hx b/std/php/Web.hx index b4cf758ed7c..5a71b1b95c0 100644 --- a/std/php/Web.hx +++ b/std/php/Web.hx @@ -130,6 +130,14 @@ class Web { header('$h: $v'); } + /** + Add an output header value. If some data have been printed, the headers have + already been sent so this will raise an exception. + **/ + public static inline function addHeader(h:String, v:String) { + header('$h: $v', false); + } + /** Set the HTTP return code. Same remark as `php.Web.setHeader()`. See status code explanation here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html From cb085ffd4e22afd9a708657d3fc132ea116206ca Mon Sep 17 00:00:00 2001 From: lublak <44057030+lublak@users.noreply.github.com> Date: Wed, 25 Dec 2019 14:53:18 +0100 Subject: [PATCH 2/2] Update Web.hx Nobody saw that! --- std/neko/Web.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/neko/Web.hx b/std/neko/Web.hx index adc79ef08a6..9ff85ec216e 100644 --- a/std/neko/Web.hx +++ b/std/neko/Web.hx @@ -113,7 +113,7 @@ class Web { Add an output header value. If some data have been printed, the headers have already been sent so this will raise an exception. **/ - public static function setHeader(h:String, v:String) { + public static function addHeader(h:String, v:String) { _cgi_add_header(untyped h.__s, untyped v.__s); }