I'm using a header-filter and a body-filter.
The header filter creates a subrequest and change the header in response
static ngx_int_t aod_response_header_filter(ngx_http_request_t *r)
if (ctx->state == ...)
// setup subrequest
res = ngx_http_subrequest(....)
// handle subrequest response
so far, this works fine. However, during the execution of the
subrequest, the response_body_filter of the main request is called. Is
there a way to postpone this until the header_filter is finished?
Thanks for your help
I'm fairly new to nginx development (although I'm fairly experienced in
Apache-development and in event driven programming) and have some
questions about the recommended design for a complex module.
What do I want to archive?
1. read header and body from an incoming request
- seems to work
2. from this original request, create a POST sub request to another server.
- seems to work. I use a sub-request to '/foo' and added a location
'/foo' which do a proxy_pass to http://foo/.
Question: Can I do this without touching the nginx.conf? I would like to
specify the IP/port of the subrequest in my handler and _not_ add a
special location to nginx.conf
3. read the whole response from this sub request into memory
Question: What is the recommended way to read and process the response
body of a sub request which shouldn't go to the client? Should I use a
body-filter or can I access the response body from my post-subrequest
handler. I tried the later but it does not work. Any example code?
4. modify the original request (header and possibly body) depending on
the data from the sub request
5. send the new main request upstream
- I assume that I simply should modify the request and return a
DECLINED to let the next handler do the work.
6. intercept the response, do a second subrequest and modify the response
- should probably done in a filter?
Another question: I want to intercept ALL requests to nginx. Which phase
would you recommend for my handler? How can I assure, that I'm the first
handler in the chain?
Thanks for you help