Hooks
Currently, the LuaFilter can register four types of hooks: input stream, output stream, one per request and one per response. You specify the type of hook in the configuration with the Script.InputFunctionName for input stream, Script.OutputFunctionName for output stream, Script.InputHeaderFunctionName for request headers and Script.OutputHeaderFunctionName for response headers.
As a side note: You can define all four hooks or only one of them in a LuaFilter configuration.
The input and output stream hook is called for every body data chunk. The function signature has three parameters:
function hookName(request, response, chunk)
-- code
return chunk
end
You have to return the body you want. If you return nil, then you will have to hold back the chunks and send the body later. That is possible and for rewriting also needed. Of course, you can also forget the body by ignoring the chunks and send in the end the data you want.
The end of the stream is marked with a nil chunk. After you got nil as a chunk, this function for this request will never be called again. So nil chunk is a good point to, for example, flush the rest of your body or send an alternative body.
The Script.InputHeaderFunctionName is only called once per request and the Script.OutputHeaderFunctionName is only called once per response. The function signature in both cases has only two parameters:
function hookName(request, response)
-- code
end
Whenever you have to deal with request headers, uri and cookies, these are the hooks you should use.