Re: accessing environment variables set by other modules

Adam Prime <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
you might want to take a look at subprocess_env

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

I don't think i've every tried to use %ENV in a Filter, perhaps it's not 
getting populated.  %ENV can be a little strange in mp2, have a look at:

http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code

though that would seem to be unrelated to your issue.

Adam


Chris Datfung wrote:
> I want to use mod-perl to edit server responses under certain 
> conditions. My plan was to use various modules, like mod-setenvif and 
> mod-security to set an environment variable and then have mod-perl edit 
> the response body only run when the environment variable is set. I tried 
> the following test which was supposed to append 'TEST' to my index.html 
> page:
> 
> in the virtual host config I have:
> 
>         SetEnvIf Request_URI "\.html$" TE=TEST
>         PerlRequire "/opt/modperl/TE/ST.pm"
>         PerlOutputFilterHandler TE::ST
> 
> the contents of /opt/modperl/TE/ST.pm is:
> ======================================================================
> package TE::ST;
> 
> use strict;
> use warnings;
> 
> use Apache2::Filter ();
> use Apache2::RequestRec ();
> use APR::Table ();
> 
> BEGIN { push @INC, "/opt/modperl/"; }
> 
> use Apache2::Const -compile => qw(OK);
> use constant BUFF_LEN => 1024;
> 
> sub handler
> {
>         my $f = shift;
> 
>         unless ($f->ctx)
>         {
>                 while ($f->read(my $buffer, BUFF_LEN))
>                 {
>                         $buffer =~ s/It/Chris/g;
>                         $buffer .= $ENV{"TE"};
>                         $f->print($buffer);
>                 }
>                 return Apache2::Const::OK;
>         }
> }
> 1;
> ========================================================================
> 
> The script correctly changes the 'It' in the index.html file to 'Chris' 
> but I don't see the value of the 'TE' variable in the response body. Can 
> someone point me to an example of how modperl can 
> access environment variables set by other apache modules?
> 
> Thanks,
> 
> - Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.