Welcome! Log In Create A New Profile


Re: mod_layout - what is wrong?

Maxim Dounin
January 06, 2010 06:40PM

On Wed, Jan 06, 2010 at 04:09:56PM +0100, witekfl Gazeta.pl wrote:

> Hi,
> http://rkd.republika.pl/ngx_http_layout_filter_module.c
> I want to write the mod_layout.
> The idea is: write all chains to temp file, at the end read it, insert the
> header after <body> and the footer before </body>.
> Sometimes it fails. There is only the header and the footer. Why?
> Could you review it?

Some random comments in random order:

1. It's probably good idea to polish style a bit before posting
code for review.

2. The whole idea of buffering to temporary file looks wrong.
There is no need to buffer more than several bytes here. And the
only case where you need buffering is when you find something like
"</b" at the end of buffer, and need next buffer to find out if
it's "</body>" or "</b>". It requires a bit more complicated
matching code, but saves lots of resources. See sub filter
and ssi filter for examples.

3. After writing chain to temp file you have to mark buffers in
this chain as sent by updating buf->pos. This will allow upper
layers to reuse this buffers. Note well: you probably want to
test your code with something like

output_buffers 1 64;

to see what happens if upper layers are out of buffers since you
don't mark them as sent. Hint: request will just hang awaiting
some buffers to become free after first 64 bytes.

4. layout_ignore_uris setting doesn't fit into nginx model of
doing things. One should write correct configuration using
"location" directives instead of doing some fancy filtering at
module level.

5. You assume buffers are in memory, but do not require it. You
should set r->filter_need_in_memory in header filter handler.

Maxim Dounin

nginx-devel mailing list
Subject Author Views Posted

mod_layout - what is wrong?

witekfl Gazeta.pl 3606 January 06, 2010 10:12AM

Re: mod_layout - what is wrong?

Maxim Dounin 1179 January 06, 2010 06:40PM

Re: mod_layout - what is wrong?

witekfl 1617 January 07, 2010 03:06PM

Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 49
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready