Bug 62359 - cannot add an output filter from lua code
Summary: cannot add an output filter from lua code
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_lua (show other bugs)
Version: 2.4-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: PatchAvailable
Depends on:
Reported: 2018-05-08 15:12 UTC by Massimiliano Calandrelli
Modified: 2018-08-04 08:02 UTC (History)
0 users

path to solve the problem (460 bytes, patch)
2018-05-08 15:12 UTC, Massimiliano Calandrelli
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Massimiliano Calandrelli 2018-05-08 15:12:57 UTC
Created attachment 35921 [details]
path to solve the problem

Output filters written in lua will only work if the filter is added to the chain by means of configuration statements.
If you need to add an output filter from lua code hooked to some earlier point in the request's lifecycle, no output will be produced.

This happens because the C code bound to the lua request_req:add_output_filter method incorrectly set the filter's context to the lua state.
The correct behaviour is to let the lua_output_filter_handle (in mod_lua.c) function create the context by setting it to NULL in the ap_add_output_filter call made by req_add_output_filter (in lua_request.c).

BTW, as far as I can see, the documentation wrongly states the function name (correct: add_output_filter, documented: addoutputfilter) and parameter's semantics, in that it can only be a filter name and not a function)
Comment 1 Christophe JAILLET 2018-08-04 08:02:17 UTC
Doc issue fixed in r1837404.
This will be available online on the next rebuilt.

The other part of your analysis makes sense to me.
I would like to test it, but I'm not sure to be able to do so in the coming days. Will look at it later.

After a quick look, 'add_output_filter()' could also be improved to mimic 'lua_ap_add_input_filter()' in order to make sanity checks (i.e. 'luaL_checktype()') and return if it has succeeded or not.