Skip to content

Commit

Permalink
add a add_header function to mod_neko HaxeFoundation#204
Browse files Browse the repository at this point in the history
  • Loading branch information
lublak committed Dec 20, 2019
1 parent 1df580c commit 98b8299
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libs/mod_neko/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ static value set_header( value s, value k ) {
return val_true;
}

/**
add_header : name:string -> val:string -> void
<doc>Add a HTTP header value</doc>
**/
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?
<doc>Get a HTTP header sent by the client</doc>
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/tools/WebServer.nml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 98b8299

Please sign in to comment.