Welcome! Log In Create A New Profile

Advanced

content handler priority

Jeff Kaufman
December 10, 2012 11:30AM
Can a module add a content handler that runs before any other content handler?

For example, if someone has:

location / {
proxy_pass ...;
}

or:

location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}

then the content handler I set with:

ngx_http_handler_pt* h = static_cast<ngx_http_handler_pt*>(
ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers));
if (h == NULL) {
return NGX_ERROR;
}
*h = my_content_handler;

won't run. I can work around this by adding location blocks like:

location ~ "\.pagespeed\.[a-z]{2}\.[^.]{10}\.[^.]+" {
# let ngx_pagespeed's content handler run
}
location ~ "^/ngx_pagespeed_static/" {
# let ngx_pagespeed's content handler run
}

but is this something I can make the ngx_pagespeed module do by
default, without configuration?

Is it safe for me to modify
cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers by inserting my handler
at the beginning instead of appending it? Will that make it run
first?

Motivation: ngx_pagespeed (a mod_pagespeed port) has two cases where
it needs to be sure it's controlling the handler. One is where the
request is for anything in the top level ngx_pagespeed_static
directory, like
"http://example.com/ngx_pagespeed_static/js_defer.0.js" and the other
is for any path like
"http://example.com/foo/bar/Puzzle.jpg.pagespeed.ce.91_WewrLtP.jpg".
These are dynamically generated, and any other handler won't know how
to produce them. My content handler already knows how to return
NGX_DECLINED for unrelated requests but it doesn't get invoked if
something else claims the content handling first.

Jeff

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

content handler priority

Jeff Kaufman 1414 December 10, 2012 11:30AM

Re: content handler priority

Piotr Sikora 538 December 10, 2012 03:18PM



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

Online Users

Guests: 187
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