Hello,
Firstly, thanks to openresty, Nginx sub-request handling which I had attempted to do via C code and was proving to be a nightmare, has now become quite easy.
I am, however, faced with some issues that I would be grateful to have some help with. Here's the situation -
---
I have a standalone module that handles requests to a location (say /hello).
I have built nginx-1.9.15 with this hello_module and lua_nginx_module.
Here is the nginx.conf -
location /test {
content_by_lua_block {
ngx.req.read_body()
local res = ngx.location.capture("/hello")
if res then
ngx.say("status: ", res.status)
ngx.say("body: ")
ngx.print(res.body)
end
}
}
This works well. When I run a POST request to http://localhost:80/test, I receive the body ("hello") returned by the /hello handler.
Now, the tricky part is that -- this hello module in the real world scenario cannot return "hello" immediately. It needs to do a lookup into a local cache and wait until a timeout, before deciding to return "hello" (cache hit) or "bye" (cache miss).
Thus, this local cache lookup is a blocking operation, which degrades the overall performance of nginx.
What I want is for this hello_module to --
- Lookup local cache.
- If cache hit, return "hello"
- If cache miss and timeout not exceeded, return NGX_AGAIN
- If timeout exceeded, return "bye"
By returning NGX_AGAIN, I expect the same hello handler to be invoked again. I do not, however, see this happening. After returning NGX_AGAIN, the hello handler is never called again.
Hope I have clarified the problem.
Any advice in this regard is greatly appreciated.
Thanks!