Multiple subrequest in handler

Adrian Perez de Castro adrianperez at
Mon Sep 10 21:41:05 MSD 2007

I think I have hit another issue related to how subrequests are
handled. I would like to add the module's built-in header and/or footer
when the subrequest fails (i.e. when subreq->headers_out.status is not
NGX_HTTP_OK), and not the error pages generated by the subrequest

Should remove them from the output chain or is there a better way of
dealing with this?

Thanks again,

El Mon, 10 Sep 2007 14:54:15 +0200
Adrian Perez de Castro <adrianperez at> escribió:

> But as it is the file listing appears at the *end* of the generated
> response. So, instead of:
>  - header (from subrequest)
>  - listing (generated in handler)
>  - footer (from subrequest)
> I am currently getting this:
>  - header (from subrequest)
>  - footer (from subrequest)
>  - listing (generated in handler)
> ...which is not a proper order at all!
> I took another look at the addition module, and it seems to be called
> *twice* per request and it controls whether to add before or after
> original content depending on the context (checking the boolean of
> ctx->before_body_sent), but about line ~160 it seems to reorder
> buffers in the output chain with this piece of code:
>     last = 0;
>     for (cl = in; cl; cl = cl->next) {
>         if (cl->buf->last_buf) {
>             cl->buf->last_buf = 0;
>             cl->buf->sync = 1;
>             last = 1;
>         }
>     }
> I am using a content handler (as autoindex does) and the addition
> module uses a filter handler... Is it enough for me if I reorder
> buffers or should I rewrite my module using a filter too?

Adrian Perez de Castro               <adrianperez at>
Oficina de Software Libre
Universidade da Coruña        
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <>

More information about the nginx mailing list