content handler priority
Jeff Kaufman
jefftk at google.com
Mon Dec 10 16:28:44 UTC 2012
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
More information about the nginx-devel
mailing list