Bug 62359

Summary: cannot add an output filter from lua code
Product: Apache httpd-2 Reporter: Massimiliano Calandrelli <massimiliano.calandrelli>
Component: mod_luaAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: NEW ---    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 2.4-HEAD   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: path to solve the problem

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.