I need to design a module that under certain conditions will produce content for the request based on data received from a local service, which is not HTTP. What I would like to do is get a request, determine that I can produce content for it, then suspend there request (presumably by returning NGX_DONE from the rewrite or access phase), then trigger a recall of the phase handler when the data is available (perhaps, multiple times), then a last recall to finalize the request.
I cannot find a good way of doing this with a C module without using sub requests, which are HTTP. Could it be possibly done in Lua? If so, would it also be possible to optimize by exposing a client socket connection to C code, which will write data to the client directly, without pumping the potentially large body through Lua? In this last case, I would ideally need to trigger only one recall of the phase handler to finalize the request.
Could someone provide a pointer for me to where I should start digging?
Many thanks in advance!