Hi, My name is Bertrand Mansion, I live in Paris, France, I have been mostly programming in PHP for the last few years and I am very excited about mod_lua since I consider Lua is superior in many ways. I have followed the development of mod_wombat and noticed that you changed the way headers_in and headers_out are accessed, they were previously tables, now only headers_in can be accessed through a headers_in() method. I have written a method to have access to headers_out as well. I am not sure it is perfect since I haven't coded with Lua and apr C APIs before and many you thought already about something more clever.
Anyway, with this patch, you can do: r:headers_out('Location', 'http://www.example.com') -- set the Location header r:headers_out('Location) -- return the current value for header Location r:headers_out('Location', nil) -- unset the Location header There might be other options I haven't implemented for example: r.headers_out['Location'] = 'http://www.example.com' -- like in previous versions of mod_wombat or r:headers_out{Location = 'http://www.example.com} -- but then it becomes harder to unset a header (?) or r.headers_out:set('Location', 'http://www.example.com') r.headers_out:get('Location') r.headers_out:unset('Location') HTH ----- Bertrand Mansion Mamasam
--- lua_request.c +++ (clipboard) @@ -447,6 +447,41 @@ return 1; } +static int req_headers_out(lua_State *L) +{ + const char *key; + const char *value; + + request_rec *r = apl_check_request_rec(L, 1); + + key = luaL_checkstring(L, 2); + + if (lua_isnone(L, 3) == 1) { + /* getting a value from headers_out */ + value = apr_table_get(r->headers_out, key); + if (value) { + lua_pushstring(L, value); + } + else { + lua_pushnil(L); + } + } + else { + if (lua_isnil(L, 3) == 1) { + value = apr_table_get(r->headers_out, key); + if (value) { + apr_table_unset(r->headers_out, key); + } + } + else { + value = luaL_checkstring(L, 3); + apr_table_set(r->headers_out, key, value); + } + } + + return 1; +} + /* handle r.status = 201 */ static int req_newindex(lua_State *L) { @@ -604,6 +639,8 @@ apr_hash_set(dispatch, "headers_in", APR_HASH_KEY_STRING, makefun(&req_headers_in, APL_REQ_FUNTYPE_LUACFUN, p)); + apr_hash_set(dispatch, "headers_out", APR_HASH_KEY_STRING, + makefun(&req_headers_out, APL_REQ_FUNTYPE_LUACFUN, p)); lua_pushlightuserdata(L, dispatch); lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch"); @@ -668,4 +705,4 @@ lua_boxpointer(L, r); luaL_getmetatable(L, "Apache2.Request"); lua_setmetatable(L, -2); -} \ No newline at end of file +}