perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Justin Luster" <>
Subject Mod_Perl 2.0 Header question
Date Tue, 16 Aug 2005 16:57:09 GMT
Hi, I was hoping to get a bit of help on how to send the proper HTTP
headers using Mod_Perl.  We create Perl scripts and then ship them out
to our clients for them to run on their servers.  The script should work
on regular CGI and Mod_Perl if they have it.  Things have worked fine so
far.  But now Mod_Perl 2.0 is starting to be installed on servers
throughout the world and I need to modify my script so that it will work
with it also.  I only use Mod_Perl to speed up regular CGI using


I have a file that "requires" a file.  In the I have the code that produces the HTTP header.  It is in the because both and need it.


My current code looks something like this:


sub PrintHeader 


            my $strOut = "";

            my $blnModPerl = 0;

            my $intModPerlVersion = 0;

            my $strDefaultContentType = "";


            $strDefaultContentType .= "Content-type: text/html\r\n\r\n";


            if (exists($ENV{'MOD_PERL'}) && defined($ENV{'MOD_PERL'})) 


                        $blnModPerl = 1;


                        $intModPerlVersion = $ENV{'MOD_PERL'};


                        # Change mod_perl/1.XX to 1.X

                        $intModPerlVersion =~



            if ($ENV{'PERL_SEND_HEADER'} || ($blnModPerl == 0)) 


                        $strOut = $strDefaultContentType;




                        my $r = Apache->request;




                        #Only call send_http_header for mod_perl
versions prior to (1.9) in the 1.26 series 

                        #Remember to update this in too

                        if ($intModPerlVersion < 1.9) 






            $authlib::blnPrintedHeaders = 1;


            return $strOut;



I find that this breaks under some versions of Mod_Perl 2.0.  I'm
working with two older versions: 1.99_07-dev and 1.99_12 both on Linux


My confusion is how to send the proper 2.0 header.  In my in-house
version Apache->request; does not seem to work.  The 2.0 documentation
says use Apache2::RequestUtil but that does not work either.  My clients
version however works with Apache->request and I'm confused as to why.


The bottom line is I want to have a function like the one above that
will work for CGI, mod_perl 1.0 and mod_perl 2.0.  I'd like this
function to be in a common library ( so that and can use it.


>From reading the documentation I realize that there is a function called
"handler()" and that you can get a hold of $r somehow.  So I tried it
out and came up with something like this:


use strict;


my $ModPerlObj = @_[0];




package main;


sub main





This seems to work because as I understand it Mod_Perl wraps up the
contents of and places it inside a function called "handler( )".
"handler( )" then receives an Apache Object.  So I'm getting it using
@_[0] and then passing it into my function.


Is this bad practice?  Any "cons" to doing it this way?


I just want a simple way to create the header.


Please help.






View raw message