You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jeff Ambrosino <jb...@gmail.com> on 2005/04/01 03:03:28 UTC

setting http output filter priority?

Hi mod_perl folks,

background: I have an http output filter working on Apache 2.0.53 with
mod_proxy, mod_cache, deflate and mod_perl 2.0.0-RC4.  My functionality
is that I'm stripping out certain types of advertising content, IMG
tags, etc.

The problem I'm seeing is that if a request can be fulfilled with content
from mod_cache, then the content itself (body) isn't available to my 
http output filter...  it's only available if the content is NOT found 
in the cache.  The browser is getting the response fine, so I know the
proxy and cache are working, it's just that my filter not being inserted
in the right place.  So I'm trying to figure out how to insert my filter
after mod_cache has found/stored the content, but before defalte.

I've studied the MP2 docs (including the 3 books I have: mp Cookbook,
Lincoln Stein's and Stas Bekman's), but really can't find anything that
tells me precisely how to insert an MP2 filter with a specific AP_FTYPE_*.

Here's a simple flow of what I'd like to have happen:

1 - mod_cache [got valid content in cache? If so, go to 4; if not, go to 2]
2 - mod_proxy [fetch content from origin web]
3 - mod_cache [content cacheable?  If so, cache it locally]
4 - *MY FILTER*
5 - deflate

How can I get MYFILTER inserted in just the right place?  (And ideally it
doesn't require modifying Apache source code to change AP_FTYPE values
for mod_cache...!)

thanks
Jeff

Re: setting http output filter priority?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Jeff Ambrosino wrote:
> I
> also think it might be a useful feature to be able to set mod_perl's
> filter priority either programmatically, or at least as a compile-time
> option.

yes, we've discussed both of these options on the dev list, so you can check
the archives for all the issues (look for something about dynamic hook
ordering on dev@ and httpd-dev@httpd.apache.org).  basically, for it to work
dynamically across all platforms we need some changes in httpd, so you
wouldn't get that in 2.0 for sure.  and I'm not sure that compile-time
options are the best recourse.

but I feel your pain - the entire hooking mechanism leaves knowing users
without a "shuffle" option, and that isn't very nice.

--Geoff

Re: setting http output filter priority?

Posted by Jeff Ambrosino <jb...@gmail.com>.
I'm logging some closure to this one...  I was able to get this to
work by modifying the priorities of
mod_perl/src/modules/perlmod_perl.c's http output filter to
AP_FTYPE_CONTENT_SET-1, and then
httpd-2.0.53/modules/experimental/mod_cache.c's cache_save and
cache_out filter to AP_FTYPE_CONTENT_SET-2.  Everything works! :)

Note this change impacts all mod_perl apps running on your system. 
There are no other conflicts with Apache's built-in handlers and
filters that I could see, although that could change in the future.  I
also think it might be a useful feature to be able to set mod_perl's
filter priority either programmatically, or at least as a compile-time
option.

thanks
Jeff


On Apr 2, 2005 9:09 AM, Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
> > So, mod_perl.c could register as AP_FTYPE_CONTENT, and mod_deflate.c could
> > register as AP_FTYPE_CONTENT_SET+1. I think this is the least invasive
> > change to get
> > things working...  do you concur?
> 
> off the top of my head that looks ok.  I just hope it doesn't muck with any
> additional filters you may need later on.
> 
> good luck :)
> 
> --Geoff
>

Re: setting http output filter priority?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> So, mod_perl.c could register as AP_FTYPE_CONTENT, and mod_deflate.c could
> register as AP_FTYPE_CONTENT_SET+1. I think this is the least invasive
> change to get
> things working...  do you concur?

off the top of my head that looks ok.  I just hope it doesn't muck with any
additional filters you may need later on.

good luck :)

--Geoff

Re: setting http output filter priority?

Posted by Jeff Ambrosino <jb...@gmail.com>.
>From looking at the code, it appears that I may need to modify
mod_perl and either
of mod_cache or mod_deflate:

mod_perl.c - line ~839
----------------------------------
    ap_register_output_filter(MP_FILTER_REQUEST_OUTPUT_NAME,
                              MP_FILTER_HANDLER(modperl_output_filter_handler),
                              AP_FTYPE_RESOURCE);		// <---------------

mod_cache.c - line ~936
----------------------------------
    cache_save_filter_handle =
        ap_register_output_filter("CACHE_SAVE",
                                  cache_save_filter,
                                  NULL,
                                  AP_FTYPE_CONTENT_SET-1);	// <---------------
[...]
    cache_out_filter_handle =
        ap_register_output_filter("CACHE_OUT",
                                  cache_out_filter,
                                  NULL,
                                  AP_FTYPE_CONTENT_SET-1);	// <---------------

mod_deflate.c - line ~845
----------------------------------
    ap_register_output_filter(deflateFilterName, deflate_out_filter, NULL,
                              AP_FTYPE_CONTENT_SET);		// <---------------

So, mod_perl.c could register as AP_FTYPE_CONTENT, and mod_deflate.c could
register as AP_FTYPE_CONTENT_SET+1. I think this is the least invasive
change to get
things working...  do you concur?

thanks,
Jeff


On Apr 1, 2005 7:02 PM, Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
> > See the problem?  MYFILTER is getting inserted before the cache is serving up
> > the content, but I really want it to go after (otherwise MYFILTER doesn't
> > see the body content).  Is there a way around this aside from
> > modifying mod_cache?
> 
> at the moment, no - the hooking mechanism in apache just isn't designed for
> this type of thing.  in apache 1.3 we could mess with the order in which
> modules ran, but not in 2.0.
> 
> an alternative to modifying mod_cache would be to modify mod_perl.  from the
> look of things, mod_cache needs to be in a specific place wrt other core
> modules, so it might be easier to just modify mod_perl.  but that would
> affect the order of all perl filters, so...
> 
> --Geoff
>

Re: setting http output filter priority?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> See the problem?  MYFILTER is getting inserted before the cache is serving up
> the content, but I really want it to go after (otherwise MYFILTER doesn't
> see the body content).  Is there a way around this aside from
> modifying mod_cache?

at the moment, no - the hooking mechanism in apache just isn't designed for
this type of thing.  in apache 1.3 we could mess with the order in which
modules ran, but not in 2.0.

an alternative to modifying mod_cache would be to modify mod_perl.  from the
look of things, mod_cache needs to be in a specific place wrt other core
modules, so it might be easier to just modify mod_perl.  but that would
affect the order of all perl filters, so...

--Geoff

Re: setting http output filter priority?

Posted by Jeff Ambrosino <jb...@gmail.com>.
Thanks for the reply Geoff...  that isn't quite the problem.  Here's a
further explanation that should better articulate it.

I've turned on debug on Apache, and this is what's currently happening
when content is found in the cache:

[Fri Apr 01 14:14:13 2005] [debug] mod_disk_cache.c(371): disk_cache:
Recalled cached URL info header www.company.com/page.html?
[Fri Apr 01 14:14:13 2005] [debug] mod_disk_cache.c(502): disk_cache:
Recalled headers for URL www.company.com/page.html?
[Fri Apr 01 14:14:13 2005] [error] --> MYFILTER called here... <--
[Fri Apr 01 14:14:13 2005] [debug] mod_cache.c(220): cache: running
CACHE_OUT filter
[Fri Apr 01 14:14:13 2005] [debug] mod_cache.c(229): cache: serving /page.html
--> where I *want* MYFILTER to go <--
[Fri Apr 01 14:14:13 2005] [debug] mod_deflate.c(468): [client
192.168.0.101] Zlib: Compressed 7233 to 2171 : URL /page.html
[Fri Apr 01 14:14:13 2005] [debug] mod_headers.c(527): headers:
ap_headers_output_filter()
[Fri Apr 01 14:14:13 2005] [debug] mod_deflate.c(468): [client
192.168.0.101] Zlib: Compressed 7233 to 2171 : URL /page.html

See the problem?  MYFILTER is getting inserted before the cache is serving up
the content, but I really want it to go after (otherwise MYFILTER doesn't
see the body content).  Is there a way around this aside from
modifying mod_cache?

thanks,
Jeff


On Mar 31, 2005 8:11 PM, Geoffrey Young <ge...@modperlcookbook.org> wrote:
> 
> > I've studied the MP2 docs (including the 3 books I have: mp Cookbook,
> > Lincoln Stein's and Stas Bekman's), but really can't find anything that
> > tells me precisely how to insert an MP2 filter with a specific AP_FTYPE_*.
> >
> > Here's a simple flow of what I'd like to have happen:
> >
> > 1 - mod_cache [got valid content in cache? If so, go to 4; if not, go to 2]
> > 2 - mod_proxy [fetch content from origin web]
> > 3 - mod_cache [content cacheable?  If so, cache it locally]
> > 4 - *MY FILTER*
> > 5 - deflate
> >
> > How can I get MYFILTER inserted in just the right place?  (And ideally it
> > doesn't require modifying Apache source code to change AP_FTYPE values
> > for mod_cache...!)
> 
> try PerlSetOutputFilter
> 
> http://perl.apache.org/docs/2.0/user/handlers/filters.html#C_PerlSetOutputFilter_
> 
> HTH
> 
> --Geoff
>

Re: setting http output filter priority?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> I've studied the MP2 docs (including the 3 books I have: mp Cookbook,
> Lincoln Stein's and Stas Bekman's), but really can't find anything that
> tells me precisely how to insert an MP2 filter with a specific AP_FTYPE_*.
> 
> Here's a simple flow of what I'd like to have happen:
> 
> 1 - mod_cache [got valid content in cache? If so, go to 4; if not, go to 2]
> 2 - mod_proxy [fetch content from origin web]
> 3 - mod_cache [content cacheable?  If so, cache it locally]
> 4 - *MY FILTER*
> 5 - deflate
> 
> How can I get MYFILTER inserted in just the right place?  (And ideally it
> doesn't require modifying Apache source code to change AP_FTYPE values
> for mod_cache...!)

try PerlSetOutputFilter

http://perl.apache.org/docs/2.0/user/handlers/filters.html#C_PerlSetOutputFilter_

HTH

--Geoff