disable input and output filters for subfolders

disable input and output filters for subfolders

am 29.07.2009 16:56:43 von Mike Barborak

i have filters working correctly for a directory on my website. there
is a subdirectory that i would like to not be passed through the
filters. can i do this through the apache conf file or do i need to
code this into my filters?

here is my apache setup:

PerlRequire "/var/www/vhosts/mydomain.com/conf/seo_startup.pl"
PerlModule HTTPRequestFilter
PerlModule HTMLFilter


PerlInputFilterHandler HTTPRequestFilter
PerlOutputFilterHandler HTMLFilter


grasping for straws, i tried to add this but it didn't work:


PerlInputFilterHandler
PerlOutputFilterHandler


is there magic to remove filters for a subdirectory or even disable
mod_perl altogether?

thanks,
mike

Re: disable input and output filters for subfolders

am 30.07.2009 18:14:27 von torsten.foertsch

On Wed 29 Jul 2009, Mike Barborak wrote:
> i have filters working correctly for a directory on my website. there
> is a subdirectory that i would like to not be passed through the
> filters. can i do this through the apache conf file or do i need to
> code this into my filters?
>
> here is my apache setup:
>
> PerlRequire "/var/www/vhosts/mydomain.com/conf/seo_startup.pl"
> PerlModule HTTPRequestFilter
> PerlModule HTMLFilter
>
>
>         PerlInputFilterHandler HTTPRequestFilter
>         PerlOutputFilterHandler HTMLFilter
>

>
> grasping for straws, i tried to add this but it didn't work:
>
>
>         PerlInputFilterHandler
>         PerlOutputFilterHandler
>

>
> 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=20
remove any filter further down the filter chain=20
($f->next->next...->remove).

Torsten

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

Re: disable input and output filters for subfolders

am 30.07.2009 18:26:05 von torsten.foertsch

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_Pe rl_Handler_

or completely:

http://perl.apache.org/docs/2.0/user/config/config.html#C_En able_

Torsten

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

Re: disable input and output filters for subfolders

am 30.07.2009 18:29:49 von Mike Barborak

excellent. thanks so much - i searched and scanned that document but
obviously not well enough. rtfm.

best,
mike


On Thu, Jul 30, 2009 at 12:26 PM, Torsten
Foertsch 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_Pe rl_Handler_
>
> or completely:
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_En able_
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>

Re: disable input and output filters for subfolders

am 01.08.2009 17:50:12 von Mike Barborak

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


PerlOptions -InputFilter -OutputFilter


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:


PerlSetVar EnableMyFilter false


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 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_Pe rl_Handler_
>
> or completely:
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_En able_
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>

Re: disable input and output filters for subfolders

am 01.08.2009 20:25:47 von torsten.foertsch

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:
>
>
> =A0 =A0 =A0 =A0PerlSetVar EnableMyFilter false
>

>
> and my input and output filter handlers would look something like
> this:
>
> sub handler : FilterRequestHandler
> {
>         my $f =3D shift;
>
>         return Apache2::Const::DECLINED if $f->r->dir_con=
fig (
> 'EnableMyFilter' ) eq 'false';
>
>         ...
> }
>
> does that approach sound correct?

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

my $ctx=3D$f->ctx;

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

$f->ctx is undefined on first invocation. So, unless defined $ctx I can=20
run checks that need to be done only once. If one of the conditions is=20
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

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