Postponing responses to requests
nginx-forum at nginx.us
Mon Mar 15 19:23:37 MSK 2010
I'm trying to figure out how to get some code working in an NGINX module we
are writing. The basic idea is that requests come in to our module, and we
make callouts from the module to both some external code and to an upstream
HTTP interface. We then want to send responses to the requests.
The bit that we are a little confused about is how to manage our responses
correctly. Our code looks a bit like this.
- Get request in our request handler
- Do some work that will trigger an async callback later (from a library)
- Return NGX_DONE to say "leave us alone for now"
- Get async callback from our handler
- Issue upstream request (using upstream module)
- Get upstream response
- Do some more processing before sending response (potentially much later after more async work)
The problem occurs in that last step; we can do our async processing and manage the upstream requests OK, but as soon as we get our response from the upstream module, we find that finalize_request is called and a response is sent. However, we want to hold off until later sending the response.
We'd like to be able to just say "don't send a response on this request just now, even though the upstream request has returned". I think perhaps the underlying issue is that we are just issuing an upstream request not a subrequest, but I'm now quite confused, and it would be very helpful if somebody could give me some helpful hints, or else point me at some documentation of how to do this, or just at some sample code we could read through for ideas.
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,64052,64052#msg-64052
More information about the nginx