From: Jim Jagielski Date: Thu, 30 Jan 2020 15:13:30 +0000 (+0000) Subject: Merge r1872455 from trunk: X-Git-Tag: 2.4.42~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=737a6dc8883b0e0ab23db03c3a229c80d4b494e6;p=thirdparty%2Fapache%2Fhttpd.git Merge r1872455 from trunk: add r/o iterable tables The current apr tables exposed support get/set but we cannot get the keys or iterate. add _table() alternatives Submitted by: covener Reviewed by: covener, jim, humbedooh git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1873367 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index ec3edf27846..ded0ecce34c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes with Apache 2.4.42 + *) 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] + *) mod_lua: Accept nil assignments to the exposed tables (r.subprocess_env, r.headers_out, etc) to remove the key from the table. PR63971. [Eric Covener] diff --git a/STATUS b/STATUS index c8b62131a68..991ed406b23 100644 --- a/STATUS +++ b/STATUS @@ -132,12 +132,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) mod_lua: add _table() methods to return raw r/o lua tables that can be - iterated over for headers/notes/subprocess_env: - trunk patch: http://svn.apache.org/r1872455 - 2.4.x patch: svn merge -c 1872455 ^/httpd/httpd/trunk - +1: covener, jim, humbedooh - *) mod_http2: Fixed rare cases where a h2 worker could deadlock the main connection. trunk patch: http://svn.apache.org/r1871810 2.4.x patch: svn merge -c 1871810 ^/httpd/httpd/trunk diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index 860e5ee07a9..7400ffaf89b 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -432,7 +432,7 @@ end table no MIME header environment for the response, printed even on errors and - persist across internal redirects + persist across internal redirects. A read-only lua table suitable for iteration is available as r:err_headers_out_table(). filename @@ -459,13 +459,13 @@ end table yes MIME header environment from the request. This contains headers such as Host, - User-Agent, Referer and so on. + User-Agent, Referer and so on. A read-only lua table suitable for iteration is available as r:headers_in_table(). headers_out table yes - MIME header environment for the response. + MIME header environment for the response. A read-only lua table suitable for iteration is available as r:headers_out_table(). hostname @@ -507,7 +507,7 @@ end notes table yes - A list of notes that can be passed on from one module to another. + 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(). options @@ -574,7 +574,7 @@ end subprocess_env table yes - The environment variables set for this request. + The environment variables set for this request. A read-only lua table suitable for iteration is available as r:subprocess_env_table(). started diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 77a88b437ec..67ff432e51f 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -307,6 +307,40 @@ static apr_status_t lua_write_body(request_rec *r, apr_file_t *file, apr_off_t * 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, table>] */ +} + +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_State *L, apr_pool_t *p) 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,