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

Reply via email to