You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de> on 2007/09/27 14:18:07 UTC

Add a new RewriteCond Variable with mod_perl in an OutputFiler - possible?

Hi.

I've read around the docs but i dont know if its possible or not.
Can an perl output filter add a new variable to the current process which can 
be analyzed by mod_rewrite?

Background:

My filter does some internal redirects.
I want to set a Condition named "ORIGINAL_REQ" to the url of the first, the 
really first request url - before the internal_redirects happened.

This way mod_rewrite can analyze the url and i can deny or permit access to 
the url.

Is this possible? If not, are there any other safe ways to do such things - 
without having to modify mod_rewrites sources.

Torsten

Re: Add a new RewriteCond Variable with mod_perl in an OutputFiler - possible?

Posted by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>.
Am Montag, 1. Oktober 2007 schrieben Sie:
> You can pass this king of data to mod_rewrite with
> $r->subprocess_env('name' => 'value') on the mod_perl side and RewriteCond
> %{ENV:name} on the mod_rewrite side.
>
> See
> http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_en
>v_

Hi, thx for this idea.
Tried it out but still got some problem - mod_rewrite debugging log shows an 
empty input - my env:var is not found/empty.
Are there any restrictions - some "calling" stuff things i should be aware 
off?
Only i guess - the "rewrite" stuff is happening before my filter gets called - 
if this is the cause, can i reorder things?

My var is named: 

RewriteCond %{ENV:ORIGINAL_REQUEST_URI} ^/extern
RewriteRule ^/extern - [R=403,F]

I am setting this variable in a request input filter - maybe a perl access 
handler would be fine here too, as i dont really need the filter object:

$r->subprocess_env("ORIGINAL_REQUEST_URI" => $prev_r->uri());

Where prev_r is a defined Request object of the initial request received.

<Location /extern/>
   PerlInputFilterHandler MyApache2::Redirect::checkAccessHandler
</Location>

Something wrong here?

Or have i have to do such things in a PerlAccessHandler (without the ENV 
stuff) - like i've done it (now), which do the trick:

pseudo code:

get request object
loop through all previos ones $r->prev_r
if prev_r eq forbidden uri == DIRECT_ACCESS
 return FORBIDDEN;
else
 #uri is reached via interal_redirect through outputfilter OK
 return OK;


Torsten

Re: Add a new RewriteCond Variable with mod_perl in an OutputFiler - possible?

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Torsten Krah wrote:
> Hi.
> 
> I've read around the docs but i dont know if its possible or not.
> Can an perl output filter add a new variable to the current process which can 
> be analyzed by mod_rewrite?
> 
> Background:
> 
> My filter does some internal redirects.
> I want to set a Condition named "ORIGINAL_REQ" to the url of the first, the 
> really first request url - before the internal_redirects happened.

You can pass this king of data to mod_rewrite with $r->subprocess_env('name' => 'value') on
the mod_perl side and RewriteCond %{ENV:name} on the mod_rewrite side.

See http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_env_

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/