Filter chain_link problem

Hi,
so I’m making my first steps with developing a nginx module. As a
starting
point I took the addition filter module replaced “addition” with
“mmaddition” everywhere and prepended an “mm” to the configuration
directives to avoid collisions. After doing that I can compile and use
this
“new” module. So far so good.

Now I’m trying to prepend a static header to a page but things are not
working as I would expect them to. Here is the code fragment I inserted
in
the filter function:

 ngx_buf_t                 *header_buffer;
 ngx_chain_t               *header_link;

     header_buffer->pos = (u_char *) "<!-- Served by Nginx -->";
     header_buffer->last = header_buffer->pos + sizeof("<!-- Served 

by
Nginx -->") - 1;
fprintf(stderr, "filter called: ");
fprintf(stderr, header_buffer->pos);

     header_link = ngx_alloc_chain_link(r->pool);
     header_link->buf = header_buffer;
     header_link->buf->last_buf = 1;
     header_link->next = NULL;

     ngx_http_set_ctx(r, NULL, ngx_http_mmaddition_filter_module);
     return ngx_http_next_body_filter(r, header_link);

The problem is that I get "filter called: " in
the
log and a response code of 200 with wget but no body at all.

I’m aware that this code doesn’t really insert anything but simply
creates
a new chain_link initialized with a buffer which then get passed on to
the
next body_filter.

My question is shouldn’t I get “” as a response
body and if not why not?

(I’ve written a filter module for apache before so I have some
experience
with this kind of bucket brigade/chain_link handling but there is
obviously
something I’m missing here.)

Regards,
Dennis

On Wed, Jan 13, 2010 at 10:17 AM, Dennis J. [email protected]
wrote:

ngx_buf_t *header_buffer;
ngx_chain_t *header_link;

   header_buffer->pos = (u_char *) "<!-- Served by Nginx -->";
   header_buffer->last = header_buffer->pos + sizeof("<!-- Served by

Nginx -->") - 1;

I haven’t looked hard, but it seems that you didn’t allocate the
ngx_buf_t object under the header_buffer pointer?

Cheers,
-agentzh

On 01/13/2010 04:05 AM, agentzh wrote:

On Wed, Jan 13, 2010 at 10:17 AM, Dennis J.[email protected] wrote:

ngx_buf_t                 *header_buffer;
ngx_chain_t               *header_link;

    header_buffer->pos = (u_char *) "<!-- Served by Nginx -->";
    header_buffer->last = header_buffer->pos + sizeof("<!-- Served by

Nginx -->") - 1;

I haven’t looked hard, but it seems that you didn’t allocate the
ngx_buf_t object under the header_buffer pointer?

Hm, thinking about it that should have been a problem.
Strangely enough things started working the moment I set
header_buffer->memory=1. Strange.
Anyway I’m already at a point where I can insert a proper header from a
file using ngx_open_cached_file().

What I noticed is that if I don’t shift+reload I always get a 304 not
modified. What is the proper way of disabling this caching in a filter
so
that the data sent is always fresh? I tried setting r->no_cache but I’m
not
even sure the filter function itself is the proper place to do that?

I also tried:

 tp = ngx_timeofday();
 r->headers_out.last_modified_time = tp->sec;

but that didn’t work either.

Regards,
Dennis