architecture of a module - processing a response from a subrequest

Piotr Sikora piotr.sikora at frickle.com
Thu Jul 29 13:45:15 MSD 2010


Hi,

> 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

Just check what "proxy_pass" directive does in the configuration phase and 
copy that behavior.

> 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?

Check eval module [1].

> 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?

What exactly are you trying to achieve? Maybe you could use 
X-Accel-Redirect, eval module or ngx_lua [2] instead?

> 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?

There is only one active content handler at the time. Unless you want to 
skip all other phases (rewrite, access, etc), which probably isn't a good 
idea.

[1] http://github.com/vkholodkov/nginx-eval-module
[2] http://github.com/chaoslawful/lua-nginx-module

Best regards,
Piotr Sikora < piotr.sikora at frickle.com >
 




More information about the nginx-devel mailing list