Welcome! Log In Create A New Profile

Advanced

Filter insertion and ordering

Nick Kew
January 08, 2013 07:36AM
OK, so my module needs to insert filters.
I put the usual in a post_config function:

/* Insert headers_out filter */
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = my_header_filter;

/* Insert body_out filter */
ngx_http_next_body_filter = ngx_http_top_body_filter;
ngx_http_top_body_filter = my_body_filter;

Only they never get called!

With the aid of gdb I put a breakpoint in my post_config,
and I see ngx_http_top_[header|body]_filters are NULL
at the point where the post_config is being called.
Must mean my module is getting called first, right?
Guess that figures if it was linked in last and works
in Apache 1.x-style order.

Setting a breakpoint in another module's filter, I get to:

613 return ngx_http_write_filter(r, &out);
(gdb) bt
#0 ngx_http_header_filter (r=0x7f7f728b6000) at ngx_http_header_filter_module.c:613
#1 0x0000000109020834 in ngx_http_chunked_header_filter (r=0x7f7f728b6000) at ngx_http_chunked_filter_module.c:68
… [more header filters] ...
#9 0x0000000108fe2945 in ngx_http_send_header (r=0x7f7f728b6000) at ngx_http_core_module.c:1941
#10 0x0000000109013def in ngx_http_upstream_send_response (r=0x7f7f728b6000, u=0x7f7f72838450) at ngx_http_upstream.c:2063

I infer ngx_http_header_filter must've inserted itself after my module,
and is not calling a "next" filter. Clearly not useful!

Apart from the obvious WTF, this raises another issue: how does my
module determine its order in the chain? Its body filter needs to come
before anything that might encode it (like compression or chunking),
but the header filter should ideally come after those operations to
see exactly what will be sent to the Client!

How do I take control?

--
Nick Kew
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Filter insertion and ordering

Nick Kew 1110 January 08, 2013 07:36AM

Re: Filter insertion and ordering

Maxim Dounin 486 January 08, 2013 08:54AM

Re: Filter insertion and ordering

Nick Kew 363 January 15, 2013 05:36AM

Re: Filter insertion and ordering

Brian Akins 484 January 15, 2013 06:56AM



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

Online Users

Guests: 214
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready