Response with mixed file + generated contents

Igor Sysoev is at
Thu Sep 6 21:44:05 MSD 2007

On Thu, Sep 06, 2007 at 06:34:25PM +0200, Adrian Perez de Castro wrote:

> First of all, I will introduce myself: my name is Adrian and I work for
> the Free Software Office of the University of A Coru??a (Spain). As part
> of our tasks here, we are maintaining a mirror of several open source
> projects (, also by ftp and rsync), which we are
> planning to migrate from Apache to Nginx.
> I am currently working on a replacement for the autoindex module
> (currently named fancyindex) which outputs XHTML tables instead of a
> big <pre> element. Also, it supports embedding a "readme" file
> (currently using an <iframe>, which is useful to embed full HTML
> documents inside the gerated indexes, but I am planning to add inline
> support as well), and finally I would like to implement configurable
> headers and footers for the listings.
> After a quick read on the server's code, I would like to know a bit more
> about how the output chain gets sent to the client, because I would
> like to do the following when custom header/footer are enabled instead
> of the builtin ones:
>  1. Send custom header: Fill in a ngx_buf_t with the details of the
>     header file.
>  2. Generate XHTML table with file listing, in a memory buffer as
>     autoindex does (and as I am doing right now). Chain it as next
>     buffer of the one created in (1).

Yes, however, see below about subrequests.

>  3. Send custom footer: Fill in a ngx_buf_t with the details of the
>     footer file. Chain it as next buffer of the one created (2).
> Currently, for the buffers created in steps (1) and (3) I am filling
> "buffer->file" with the file info values, setting "buffer->last" to
> the length of the file and "buffer->in_file" to 1.
> Can someone confirm that it is ok and Nginx will open and send the
> file for me? (I will be experimenting myself in the meanwhile, too).

No, nginx does not open the file by itself. See ngx_http_static_module
that sends files.

> Also, will Nginx notice I filled in the "buffer->file" member and use
> "sendfile()" if possible? (or any other method which the server will
> consider "optimal").

If sendfile is enabled and file content is not needed to be in memory
(gzip, ssi, charset, etc.) then the content will be sent via sendfile().

However, it's better to include header/footer via subrequest as Evan
has suggested.

> Although I am aware my module will not be as fast as the built-in
> autoindex module, I am trying to make it as efficient as possible, and
> I have been reading portions of Nginx code to keep up with it -- and I
> found it very clean and interesting to read, which I think is a Good
> Thing(tm).
> Thank you in advance, and for such a wonderful piece of software!
> P.S. If someone is interested, I can publish the repository with the
> code of module, it is BSD-licensed as Nginx.

Igor Sysoev

More information about the nginx mailing list