You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matt Avitable <mj...@escapement.net> on 2003/03/04 06:54:30 UTC

[mp2] disabling a perl handler within a specific location

Hi list :-)

Does anyone know how one goes about disabling a particular handler 
within a specific location?  For example, consider the following:

    <Location />
         PerlInitHandler config
         PerlOutputFilterHandler filter
     </Location>

    <LocationMatch "/(images|gfx)/">
	## what can I put here to say "don't run" to the above handlers?
    </Location>

## OR

     <Files ~ "\.(jpg|jpe?g|gif|png)$">
         ## something here...
     </Files>

For all HTTP requests for files everywhere excluding directories with 
/images/ and /gfx/ in it, I want to
run my PerlInitHandler and my PerlOutputFilterHandler.  All my handlers 
do is set up some config variables
and run an xml filter.  It's useless overhead to run these handlers on 
images.

I'd change the directory structure so the image dirs and the perl 
locations don't overlap, but its just not practical for this app.
I figure I can test for file/mime types of the requested file in my 
handlers, but I'd love to be able to deal with this issue from within 
httpd.conf.

Here is my setup, in case you need it:
mp 1.99_08
apache 2.0.44
Linux RH > 7.2

I would appreciate any thoughts about this at all!  Even a 'I think 
your going about this entirely the wrong way' would be helpful.  This 
is all development software I'm working on, so I'm free to change alot.

Thanks!

-m

## Matt J. Avitable (mja@escapement.net)
## General Partner / Programmer
## Escapement Arts And Media

## http://www.escapement.net/
## Phone: (804) 400-0605


Re: [mp2] disabling a perl handler within a specific location

Posted by Thomas Klausner <do...@zsi.at>.
Hi!

On Tue, Mar 04, 2003 at 12:54:30AM -0500, Matt Avitable wrote:

> Does anyone know how one goes about disabling a particular handler 
> within a specific location?  For example, consider the following:
> 
>    <Location />
>         PerlInitHandler config
>         PerlOutputFilterHandler filter
>     </Location>
> 
>    <LocationMatch "/(images|gfx)/">
> 	## what can I put here to say "don't run" to the above handlers?
>    </Location>

This works for Auth*Handlers, so it should work for any phase:

    <LocationMatch "/(images|gfx)/">
       PerlInitHandler Apache::Constants::OK
    </Location>

See recipy 7.3 in the Cookbook


-- 
#!/usr/bin/perl                               http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Re: [mp2] disabling a perl handler within a specific location

Posted by Stas Bekman <st...@stason.org>.
Matt Avitable wrote:
> Hi list :-)
> 
> Does anyone know how one goes about disabling a particular handler 
> within a specific location?  For example, consider the following:
> 
>    <Location />
>         PerlInitHandler config
>         PerlOutputFilterHandler filter
>     </Location>
> 
>    <LocationMatch "/(images|gfx)/">
>     ## what can I put here to say "don't run" to the above handlers?
>    </Location>
> 
> ## OR
> 
>     <Files ~ "\.(jpg|jpe?g|gif|png)$">
>         ## something here...
>     </Files>
> 
> For all HTTP requests for files everywhere excluding directories with 
> /images/ and /gfx/ in it, I want to
> run my PerlInitHandler and my PerlOutputFilterHandler.  All my handlers 
> do is set up some config variables
> and run an xml filter.  It's useless overhead to run these handlers on 
> images.

This is not really a mp2 specific question I believe, unless I'm missing 
something. You have to do the same in mp1.

I guess there might be a way to do that, but the simplest idiomatic modperl 
approach is to make the decisions once you are inside the Init handler.

   <Location />
          PerlInitHandler Foo::handler
   </Location>

package Foo;
# load the modules/constants here
sub handler {
   my $r = shift;
   return Apache::DECLINED if $r->uri =~ /(?:jpe?g|gif|png)$/;
   $r->push_handlers(PerlOutputFilterHandler => \&filter_handler);
   return Apache::OK;
}
1;

p.s. I've optimized your /jpg|jpe?g/ regex ;)

Also you may need this :)
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com