Subrequests and output filters

Maxime Henrion mhenrion at appnexus.com
Fri Aug 7 11:33:06 UTC 2015


Thanks for the answer.

I have tried using the NGX_HTTP_SUBREQUEST_IN_MEMORY flag and a post subrequest callback; in fact the code I copy-pasted uses those. However, I don't see how to get at the response's body from this callback. Looking at the SSI module code, the ngx_http_ssi_stub_output() post subrequest callback does some consistency checks, sets the headers if they haven't been set already, and then just calls into ngx_http_output_filter() with a buffer chain that was actually passed to it through the "data" field of the post subrequest handler structure.

I'm obviously missing things here, but I don't understand how to get at that response's body still.

Thanks,
Maxime

________________________________________
From: nginx-devel [nginx-devel-bounces at nginx.org] on behalf of Maxim Dounin [mdounin at mdounin.ru]
Sent: Wednesday, August 05, 2015 8:55 PM
To: nginx-devel at nginx.org
Subject: Re: Subrequests and output filters

Hello!

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 http://nginx.org/en/docs/http/ngx_http_ssi_module.html
for docs).

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-devel mailing list
nginx-devel at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel



More information about the nginx-devel mailing list