Subrequests and output filters

Maxim Dounin mdounin at
Wed Aug 5 18:55:48 UTC 2015


On Wed, Aug 05, 2015 at 11:21:52AM +0000, Maxime Henrion wrote:


> NOTE: I'm not sure whether NGX_DONE above is the correct enum 
> value to use, but I have tried NGX_AGAIN and others as well to 
> no avail.

NGX_DONE is correct return code.  Compare with proxy and/or dav 
modules code if unsure.


> As of right now, I have simply never been able to get ateven a 
> response body for one of those subrequests. I have verified that 
> the subrequests are indeed being sent, and that nginx reads the 
> response to completion (using netcat and sending an invalid 
> response prompts a log message about an invalid HTTP response), 
> but my output body filter is simply never being invoked, and as 
> far as I know this is the only way I have to get at the response 
> body here. I have not been able to use the post_subrequest 
> callback either, and am unsure if it'd be useful in my case.

So, the problem you are facing now is that your body filter is not 
called, right?   Most likely reason, I think, is that your module 
is registered at a wrong place during configuration, and that's 
why it's not being called.  To make sure your filter is called you 
should register it at HTTP_AUX_FILTER_MODULES list in the config 
file of your module.

Alternatively, you may consider using the 
NGX_HTTP_SUBREQUEST_IN_MEMORY flag to ngx_http_subrequest().   
This will allow you to get a response body in a post subrequest 
callback, without writing any response body filters.  See 
src/http/modules/ngx_http_ssi_filter_module.c for a usage example, 
it's used to implement the "set" parameter of the "include" SSI 
command (see 
for docs).

Maxim Dounin

More information about the nginx-devel mailing list