You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mike Barborak <ba...@basikgroup.com> on 2009/08/01 17:50:12 UTC

Re: disable input and output filters for subfolders

so when i tried the httpd.conf approach i ran into a problem. i added
this to my conf file:

<Directory /var/www/vhosts/mydomain.com/httpdocs/test>
       PerlOptions -InputFilter -OutputFilter
</Directory>

but when i ran "apachectl -t" on it i got this syntax error:

Invalid per-directory PerlOption: InputFilter

so it seems that while PerlOption is allowed at the directory level,
the InputFilter and OutputFilter options are not. (i actually couldn't
find a relevant section in the docs about that so i am unsure.)

it is my preferred solution to be able to turn the filter off for
particular directories via the conf file so it is my fading hope that
i'm doing something wrong?

if i am not then my plan of attack is to use PerlSetVar. then my conf
file would look like so:

<Directory /var/www/vhosts/mydomain.com/httpdocs/test>
       PerlSetVar EnableMyFilter false
</Directory>

and my input and output filter handlers would look something like this:

sub handler : FilterRequestHandler
{
	my $f = shift;

	return Apache2::Const::DECLINED if $f->r->dir_config (
'EnableMyFilter' ) eq 'false';

	...
}

does that approach sound correct?

or is that i need to add an enabling / disabling filter into the
filter chain in front of my filter that reads the PerlSetVar option
and then either leaves my filter in the chain or uses something like
"$f->next->next...->remove" to remove it?

thanks,
mike


On Thu, Jul 30, 2009 at 12:26 PM, Torsten
Foertsch<to...@gmx.net> wrote:
> On Thu 30 Jul 2009, Torsten Foertsch wrote:
>
> Sorry, I hit return while one of my left hand fingers rested on the CTRL
> key and the MUA interpreted this as "send mail now".
>
> So, here comes the rest of what I wanted to say.
>
>> On Wed 29 Jul 2009, Mike Barborak wrote:
>> > is there magic to remove filters for a subdirectory or even disable
>> > mod_perl altogether?
>>
>> A filter can remove itself on first invocation ($f->remove). It can
>> also remove any filter further down the filter chain
>> ($f->next->next...->remove).
>
> So, you can write a simple filter that checks things and removes the
> next filter in the chain if necessary. Then you insert this filter
> right before the unwanted one.
>
> You can also disable mod_perl for certain request phases:
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_Perl_Handler_
>
> or completely:
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_Enable_
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>

Re: disable input and output filters for subfolders

Posted by Torsten Foertsch <to...@gmx.net>.
On Sat 01 Aug 2009, Mike Barborak wrote:
> Invalid per-directory PerlOption: InputFilter
>
> so it seems that while PerlOption is allowed at the directory level,
> the InputFilter and OutputFilter options are not. (i actually
> couldn't find a relevant section in the docs about that so i am
> unsure.)

This might quite be true.

> it is my preferred solution to be able to turn the filter off for
> particular directories via the conf file so it is my fading hope that
> i'm doing something wrong?
>
> if i am not then my plan of attack is to use PerlSetVar. then my conf
> file would look like so:
>
> <Directory /var/www/vhosts/mydomain.com/httpdocs/test>
>        PerlSetVar EnableMyFilter false
> </Directory>
>
> and my input and output filter handlers would look something like
> this:
>
> sub handler : FilterRequestHandler
> {
>         my $f = shift;
>
>         return Apache2::Const::DECLINED if $f->r->dir_config (
> 'EnableMyFilter' ) eq 'false';
>
>         ...
> }
>
> does that approach sound correct?

Almost, it would be better to have the filter remove itself on first 
invocation if it's not needed. A typical filter of mine looks like 
this:

  my $ctx=$f->ctx;

  unless( defined $ctx ) {
    unless( check_conditions($f) ) {
      $f->remove;
      return Apache2::Const::DECLINED;
    }
    $f->ctx($ctx=[]);
    $f->r->headers_out->unset('Content-Length');
  }
  ...

$f->ctx is undefined on first invocation. So, unless defined $ctx I can 
run checks that need to be done only once. If one of the conditions is 
not met the filter removes itself and returns DECLINED.

You'll have to place your PerlVar check instead of check_conditions.

> or is that i need to add an enabling / disabling filter into the
> filter chain in front of my filter that reads the PerlSetVar option
> and then either leaves my filter in the chain or uses something like
> "$f->next->next...->remove" to remove it?

No, this is only a last resort if you cannot change the filter itself.

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net