From 98b82993e0de23568ae3accd041e3a1774c530e5 Mon Sep 17 00:00:00 2001 From: lublak Date: Fri, 20 Dec 2019 20:51:49 +0100 Subject: [PATCH] add a add_header function to mod_neko #204 --- libs/mod_neko/cgi.c | 18 ++++++++++++++++++ src/tools/WebServer.nml | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/libs/mod_neko/cgi.c b/libs/mod_neko/cgi.c index 017b8a27..388bafc1 100644 --- a/libs/mod_neko/cgi.c +++ b/libs/mod_neko/cgi.c @@ -188,6 +188,23 @@ static value set_header( value s, value k ) { return val_true; } +/** + add_header : name:string -> val:string -> void + Add a HTTP header value +**/ +static value add_header( value s, value k ) { + mcontext *c = CONTEXT(); + val_check(s,string); + val_check(k,string); + HEADERS_NOT_SENT("Header"); + if( strcmpi(val_string(s),"Content-Type") == 0 ) { + c->content_type = alloc_string(val_string(k)); + c->r->content_type = val_string(c->content_type); + } else + ap_table_add(c->r->headers_out,val_string(s),val_string(k)); + return val_true; +} + /** get_client_header : name:string -> string? Get a HTTP header sent by the client @@ -594,6 +611,7 @@ DEFINE_PRIM(get_params,0); DEFINE_PRIM(get_params_string,0); DEFINE_PRIM(get_post_data,0); DEFINE_PRIM(set_header,2); +DEFINE_PRIM(add_header,2); DEFINE_PRIM(set_return_code,1); DEFINE_PRIM(get_client_header,1); DEFINE_PRIM(get_client_headers,0); diff --git a/src/tools/WebServer.nml b/src/tools/WebServer.nml index 60a38247..006a94c9 100644 --- a/src/tools/WebServer.nml +++ b/src/tools/WebServer.nml @@ -333,6 +333,12 @@ function set_header(c,n,v) { c.headers := (n,v) :: List.filter (function((n2,_)) { n != n2 }) c.headers; } + +function add_header(c,n,v) { + headers_not_sent c n; + c.headers := (n,v) :: c.headers; +} + var cur_client : client option ref = &None; var cur_request : http_request option ref = &None; @@ -427,6 +433,11 @@ function init_mod_neko() { headers_not_sent c name; set_header c name val; }); + def "add_header" (function(name,val) { + var c = client(); + headers_not_sent c name; + add_header c name val; + }); def "get_client_header" (function(name) { match header name request().headers { | None -> neko "null"