Bug 53064 - Missing parsebody function in mod_lua
Summary: Missing parsebody function in mod_lua
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_lua (show other bugs)
Version: 2.5-HEAD
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-11 16:41 UTC by Daniel Gruno
Modified: 2012-08-21 16:12 UTC (History)
0 users



Attachments
Patch for adding the parsebody function (1.95 KB, patch)
2012-06-20 11:06 UTC, Daniel Gruno
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Gruno 2012-04-11 16:41:00 UTC
According to the mod_lua documentation, there should be a function called r:parsebody, which parses the POST data and converts it into a Lua table, but I have yet to actually find this function declared inside the mod_lua code.

With 2.4, adding this functionality should be pretty straightforward: 
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* r:parsebody() returning a lua table */
static int req_parsebody(lua_State *L)
{
    apr_array_header_t          *fields;
    int                         i;
    apr_table_entry_t           *e = 0;
    request_rec *r = ap_lua_check_request_rec(L, 1);
    lua_newtable(L);
    lua_newtable(L);            /* [table, table] */
    ap_parse_form_data(r, NULL, &fields, -1, MAX_STRING_LEN); /* Maybe increase this value? */
    e = (apr_table_entry_t *) fields->elts;
    for(i = 0; i < fields->nelts; i++) {
        req_aprtable2luatable_cb(L, e[i].key, e[i].val);
    }
    return 2;                   /* [table<string, string>, table<string, array<string>>] */
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

(The function would also have to be declared in ap_lua_load_request_lmodule)

I hope this little snippet will at least give some food for thought, and I hope that the issue can be resolved at some point in time, as we clearly need more Lua in the world.
Comment 1 Eric Covener 2012-04-11 16:50:12 UTC
IMO mod_lua enhancement or doc defect -- setting to enhancement
Comment 2 Daniel Gruno 2012-06-20 11:06:30 UTC
Created attachment 28968 [details]
Patch for adding the parsebody function

This patch adds the parsebody function to the Lua environment, so scripts can access POST data from requests.
Comment 3 Daniel Gruno 2012-06-20 11:28:19 UTC
Added the function to trunk, r1352047
Comment 4 Rainer Jung 2012-08-21 16:12:56 UTC
Applied in r1365539 to 2.4.x.
Released with 2.4.3.