diff --git a/example/test.html b/example/test.html index 61bd4c6..2ac2b00 100644 --- a/example/test.html +++ b/example/test.html @@ -4,6 +4,13 @@

Remote Host: <%=_UHTTP["REMOTE_HOST"]%>

Url: <%=_UHTTP["HTTP_URL"]%>

Path: <%=_UHTTP["HTTP_PATH"]%>

+ +

------------Http Headers-------------

<%for k, v in pairs(_UHTTP["HEADERS"]) do%>

<%=k%>: <%=v%>

<%end%> + +

------------Http Variables-------------

+<%for k, v in pairs(_UHTTP["VARIABLES"]) do%> +

<%=k%>: <%=v%>

+<%end%> diff --git a/src/template.c b/src/template.c index 3411fe9..b38745a 100755 --- a/src/template.c +++ b/src/template.c @@ -565,6 +565,17 @@ static void child_cb(struct ev_loop *loop, ev_child *w, int revents) ev_child_stop(con->srv->loop, w); } +static bool found_var(struct uh_str *key, struct uh_str *val, void *udata) +{ + lua_State *L = (lua_State *)udata; + + lua_pushlstring(L, key->at, key->len); + lua_pushlstring(L, val->at, val->len); + lua_settable(L, -3); + + return false; +} + void uh_template(struct uh_connection *con) { struct template_parser *parser; @@ -638,6 +649,10 @@ void uh_template(struct uh_connection *con) lua_setfield(L, -2, "HEADERS"); + lua_newtable(L); + uh_foreach_var(con, found_var, L); + lua_setfield(L, -2, "VARIABLES"); + lua_setglobal(L, "_UHTTP"); if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) < 0) {