You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2020/01/07 19:18:13 UTC
svn commit: r1872455 - in /httpd/httpd/trunk: CHANGES
docs/manual/mod/mod_lua.xml modules/lua/lua_request.c
Author: covener
Date: Tue Jan 7 19:18:13 2020
New Revision: 1872455
URL: http://svn.apache.org/viewvc?rev=1872455&view=rev
Log:
add r/o iterable tables
The current apr tables exposed support get/set but we cannot get the keys
or iterate. add _table() alternatives
Modified:
httpd/httpd/trunk/CHANGES
httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
httpd/httpd/trunk/modules/lua/lua_request.c
Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1872455&r1=1872454&r2=1872455&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Jan 7 19:18:13 2020
@@ -1,6 +1,10 @@
-*- coding: utf-8 -*-
Changes with Apache 2.5.1
+ *) mod_lua: Add r:headers_in_table, r:headers_out_table, r:err_headers_out_table,
+ r:notes_table, r:subprocess_env_table as read-only native table alternatives
+ that can be iterated over. [Eric Covener]
+
*) configure: Add manualdir and proxycachedir to the APR_ENABLE_LAYOUT macro call.
[Graham Leggett]
Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.xml?rev=1872455&r1=1872454&r2=1872455&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_lua.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Tue Jan 7 19:18:13 2020
@@ -432,7 +432,7 @@ end
<td>table</td>
<td>no</td>
<td>MIME header environment for the response, printed even on errors and
- persist across internal redirects</td>
+ persist across internal redirects. A read-only lua table suitable for iteration is available as r:err_headers_out_table().</td>
</tr>
<tr>
<td><code>filename</code></td>
@@ -459,13 +459,13 @@ end
<td>table</td>
<td>yes</td>
<td>MIME header environment from the request. This contains headers such as <code>Host,
- User-Agent, Referer</code> and so on.</td>
+ User-Agent, Referer</code> and so on. A read-only lua table suitable for iteration is available as r:headers_in_table().</td>
</tr>
<tr>
<td><code>headers_out</code></td>
<td>table</td>
<td>yes</td>
- <td>MIME header environment for the response.</td>
+ <td>MIME header environment for the response. A read-only lua table suitable for iteration is available as r:headers_out_table().</td>
</tr>
<tr>
<td><code>hostname</code></td>
@@ -507,7 +507,7 @@ end
<td><code>notes</code></td>
<td>table</td>
<td>yes</td>
- <td>A list of notes that can be passed on from one module to another.</td>
+ <td>A list of notes that can be passed on from one module to another. A read-only lua table suitable for iteration is available as r:notes_table().</td>
</tr>
<tr>
<td><code>options</code></td>
@@ -574,7 +574,7 @@ end
<td><code>subprocess_env</code></td>
<td>table</td>
<td>yes</td>
- <td>The environment variables set for this request.</td>
+ <td>The environment variables set for this request. A read-only lua table suitable for iteration is available as r:subprocess_env_table().</td>
</tr>
<tr>
<td><code>started</code></td>
Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1872455&r1=1872454&r2=1872455&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Tue Jan 7 19:18:13 2020
@@ -307,6 +307,40 @@ static apr_status_t lua_write_body(reque
return rc;
}
+/* expose apr_table as (r/o) lua table */
+static int req_aprtable2luatable(lua_State *L, apr_table_t *t)
+{
+ lua_newtable(L);
+ lua_newtable(L); /* [table, table] */
+ apr_table_do(req_aprtable2luatable_cb, L, t, NULL);
+ return 2; /* [table<string, string>, table<string, array<string>>] */
+}
+
+static int req_headers_in_table(lua_State *L)
+{
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ return req_aprtable2luatable(L, r->headers_in);
+}
+static int req_headers_out_table(lua_State *L)
+{
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ return req_aprtable2luatable(L, r->headers_out);
+}
+static int req_err_headers_out_table(lua_State *L)
+{
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ return req_aprtable2luatable(L, r->err_headers_out);
+}
+static int req_notes_table(lua_State *L)
+{
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ return req_aprtable2luatable(L, r->notes);
+}
+static int req_subprocess_env_table(lua_State *L)
+{
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ return req_aprtable2luatable(L, r->subprocess_env);
+}
/* r:parseargs() returning a lua table */
static int req_parseargs(lua_State *L)
{
@@ -2814,14 +2848,24 @@ void ap_lua_load_request_lmodule(lua_Sta
makefun(&req_proxyreq_field, APL_REQ_FUNTYPE_STRING, p));
apr_hash_set(dispatch, "headers_in", APR_HASH_KEY_STRING,
makefun(&req_headers_in, APL_REQ_FUNTYPE_TABLE, p));
+ apr_hash_set(dispatch, "headers_in_table", APR_HASH_KEY_STRING,
+ makefun(&req_headers_in_table, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "headers_out", APR_HASH_KEY_STRING,
makefun(&req_headers_out, APL_REQ_FUNTYPE_TABLE, p));
+ apr_hash_set(dispatch, "headers_out_table", APR_HASH_KEY_STRING,
+ makefun(&req_headers_out_table, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "err_headers_out", APR_HASH_KEY_STRING,
makefun(&req_err_headers_out, APL_REQ_FUNTYPE_TABLE, p));
+ apr_hash_set(dispatch, "err_headers_out_table", APR_HASH_KEY_STRING,
+ makefun(&req_err_headers_out_table, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "notes", APR_HASH_KEY_STRING,
makefun(&req_notes, APL_REQ_FUNTYPE_TABLE, p));
+ apr_hash_set(dispatch, "notes_table", APR_HASH_KEY_STRING,
+ makefun(&req_notes_table, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "subprocess_env", APR_HASH_KEY_STRING,
makefun(&req_subprocess_env, APL_REQ_FUNTYPE_TABLE, p));
+ apr_hash_set(dispatch, "subprocess_env_table", APR_HASH_KEY_STRING,
+ makefun(&req_subprocess_env_table, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "flush", APR_HASH_KEY_STRING,
makefun(&lua_ap_rflush, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "port", APR_HASH_KEY_STRING,