Reorder output chain when subrequests are used

agentzh agentzh at
Sat May 4 18:42:04 UTC 2013


On Fri, May 3, 2013 at 3:28 PM, Marat Dakota wrote:
> Ok, I need improper way then. Just some way.
> The problem is that I know "bbb" only after the subrequest is made. And
> subrequest's body is being completely filtered by body filter. So, in fact I
> will not have "ccc", just "aaabbb", but I can't flush "bbb" out because it
> waits for the subrequest to be done.

Well, I ran into this problem while working on the "light thread"
model [1] for my ngx_lua module months ago.

The default Nginx subrequest setup ensures the output order by means
of ngx_http_postpone_filter_module and r->postponed. So we need
workarounds here.

The solution I end up with is to write my own version of the
ngx_http_subrequest function in ngx_lua and temporarily switch the
current active request (i.e., r->connection->data) to the parent
request every time the parent request is trying to output something
when there's still pending subrequests running (so as to bypass
ngx_http_postpone_filter_module). This works pretty well.

You can check out the ngx_lua module's source for more details

especially the file src/ngx_http_lua_subrequest.c.

Among other things, maybe you want to consider directly using ngx_lua
instead of writing your own Nginx C module for this task.

Best regards,


More information about the nginx-devel mailing list