Re: ordering output filters
Thanks, Nick & Ben! On Mon, Mar 14, 2011 at 1:31 PM, Nick Kew wrote: > > AP_FTYPE_RESOURCE+1. That also leaves an admin the possibility of > overriding it. I didn't realize these +1/-1 hacks were available for this API. This looks really simple & is the direction I'm leaning. > Why not an insert_filter hook? This is a really good question: I didn't know about this hook. Is there a good place I should go to learn about these hooks myself? Of course, asking this mailing-list has worked really well so far thanks to Ben & yourself & others. And in particular, adding an insert_filter hook sounds a little more complex than the AP_FTYPE_RESOURCE+1 idea. Is there some advantage to using insert_filter hook? -Josh
Re: ordering output filters
On 14 Mar 2011, at 15:54, Joshua Marantz wrote: > if (mod_includes was enabled in this config) { >re-insert mod_pagespeed at the end of the AP_FTYPE_RESOURCE chain >pass the buckets to mod_includes > } Not good. Modules are there to serve the server admin, not to enslave him. In general they shouldn't touch each other (except through public APIs) nor second-guess a server admin. In practical terms, what about a third-party module that parses comments? If includes get special treatment but others don't, you're making things horribly confusing for your users. A traditional but only slightly less ugly hack would be to declare your filter AP_FTYPE_RESOURCE+1. That also leaves an admin the possibility of overriding it. > Or can we, at init time, call server APIs to tweak the filter order? Is > there any filter that seeks to do that somehow? You could take a look at how mod_proxy_html inserts mod_xml2enc if available. > A third idea is to exploit the fact that INCLUDES adds itself to the output > chain via > ap_hook_fixups(include_fixup, NULL, NULL, APR_HOOK_LAST); > where include_fixup() does ap_add_output_filter("INCLUDES", NULL, r, > r->connection); Why not an insert_filter hook? That would be the right place to go, but then be sure to document exactly how it works and what other modules will be auto-configured. -- Nick Kew Available for work, contract or permanent http://www.webthing.com/~nick/cv.html
Re: ordering output filters
On Mon, Mar 14, 2011 at 16:54, Joshua Marantz wrote: > Even in the absence of 'remove_comments', it would be preferable to have > mod_pagespeed run after mod_includes so that it has an opportunity to > optimize the included text. The user can achieve this by putting this line > into his config file: > > AddOutputFilter INCLUDES;MOD_PAGESPEED_OUTPUT_FILTER html > > But this is not desirable for a couple of reasons. We'd like to force the > correct order automatically if possible. > We also have a constraint that mod_pagespeed must run before mod_deflate. > Actually mod_pagespeed already inserts mod_deflate in the filter-chain to > run downstream of it: > > ap_add_output_filter("DEFLATE", NULL, request, request->connection); mod_include runs at AP_FTYPE_RESOURCE, mod_deflate at AP_FTYPE_CONTENT_SET. If you register your filter at AP_FTYPE_RESOURCE + 1 or AP_FTYPE_CONTENT_SET - 1, it will run after mod_include but before mod_deflate.
ordering output filters
Hello from mod_pagespeed again. Our users have identified another incompatibility between standard filters and mod_pagespeed; this time with mod_includes. In general I think that mod_pagespeed should run after mod_includes, for a few reasons. But in particular, mod_pagespeed, in its own html-centric filter architecture, has a 'remove_comments' filter which strips out any server-side includes if mod_pagespeed runs prior to mod_includes. While 'remove_comments' is an optional feature for mod_pagespeed (many web pages would be broken without mod_pagespeed), many consider it a desirable feature they'd like to turn on. This is all documented at length in http://code.google.com/p/modpagespeed/issues/detail?id=182 Even in the absence of 'remove_comments', it would be preferable to have mod_pagespeed run after mod_includes so that it has an opportunity to optimize the included text. The user can achieve this by putting this line into his config file: AddOutputFilter INCLUDES;MOD_PAGESPEED_OUTPUT_FILTER html But this is not desirable for a couple of reasons. We'd like to force the correct order automatically if possible. The question for this mailing list is how best to achieve that. Should we, in mod_pagespeed's output filter, have logic that says: if (mod_includes was enabled in this config) { re-insert mod_pagespeed at the end of the AP_FTYPE_RESOURCE chain pass the buckets to mod_includes } Or can we, at init time, call server APIs to tweak the filter order? Is there any filter that seeks to do that somehow? We also have a constraint that mod_pagespeed must run before mod_deflate. Actually mod_pagespeed already inserts mod_deflate in the filter-chain to run downstream of it: ap_add_output_filter("DEFLATE", NULL, request, request->connection); Another hack is to have mod_pagespeed introduce a new output filter, MOD_PAGESPEED_REORDER which would: remove INCLUDES remove MOD_PAGESPEED_OUTPUT_FILTER add INCLUDES add MOD_PAGESPEED_OUTPUT_FILTER This seems ugly though because (a) I don't know how to remove a filter by name and (b) it would wind up adding INCLUDES even if it was not already registered. A third idea is to exploit the fact that INCLUDES adds itself to the output chain via ap_hook_fixups(include_fixup, NULL, NULL, APR_HOOK_LAST); where include_fixup() does ap_add_output_filter("INCLUDES", NULL, r, r->connection); I suppose mod_pagespeed could set up its own call to ap_hook_fixups(niod_pagespeed_fixup, NULL, NULL, APR_HOOK_LAST* + 1*); and add itself as an output filter. But all of these ideas seem like a hack. Any hints on how to enforce the output-filter ordering: INCLUDES,MOD_PAGESPEED,DEFLATE in a robust and clean way, would be greatly appreciated. -Josh