You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Justin Luster <ju...@sawtoothsoftware.com> on 2005/09/14 18:17:10 UTC
Do I need Apache2::RequestUtil::request( )?
Hi,
I'm still struggling with trying to understand how Mod_Perl 2 works.
All I want to do is to have a regular Perl script run under Mod_Perl
just to speed it up.
In the past, in Mod_Perl 1 I've used this:
sub PrintHeader
{
if ($ENV{'PERL_SEND_HEADER'})
{
print "Content-type: text/html\r\n\r\n";
}
else
{
my $r = Apache->request;
$r->content_type('text/html');
$r->send_http_header;
}
}
I then read the documentation where it says:
Apache->request has been replaced with Apache2::RequestUtil::request( ).
There is also some other documentation in that section that I don't
quite understand. In testing and messing around with this in Mod_Perl 2
I've noticed that the simple
print "Content-type: text/html\r\n\r\n";
just works. My Apache configuration looks like this:
<Directory C:\Apache2\Apache2\htdocs\develop>
Options ExecCGI
AddHandler cgi-script .pl
AddHandler cgi-script .cgi
#For ModPerl Only
<IfModule mod_perl.c>
<Files ~ (\.pl)>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlOptions +ParseHeaders
</Files>
</IfModule>
</Directory>
I'm thrilled if:
print "Content-type: text/html\r\n\r\n";
just works. But I want to make sure I understand it and that it is OK
before releasing this.
I'm just using ModPerl::Registry to speed regular Perl CGI scripts up.
The code needs to work with regular CGI, Mod_Perl 1, Mod_Perl 1.99, and
Mod_Perl 2.
And by the way $ENV{'PERL_SEND_HEADER'} does not seem to exist any more.
Is this not available in Mod_Perl 2?
How do detect:
PerlOptions -ParseHeaders?
Thanks for your help,
Justin
Re: Do I need Apache2::RequestUtil::request( )?
Posted by Foo Ji-Haw <jh...@nexlabs.com>.
There's not much changes to mp2, from your usage angle.
In mp1, you use Apache::Request
In mp2, the module is now called Apache2::RequestUtil. But it has generally the same methods as its mp1 equivalent, including ->request().
You get the Apache2::RequestUtil the same way as in mp1:
sub handler
{
my $r = shift;
...
}
You should also consider using Apache2::Request as a replacement for CGI:
my $request = Apache2::Request->new($r);
print $request->param('paramkey');
The 'preferred way' to set content type is simply:
$r->content_type('text/html');
Hope this helps.
----- Original Message -----
From: Justin Luster
To: 'mod_perl List'
Sent: Thursday, September 15, 2005 12:17 AM
Subject: Do I need Apache2::RequestUtil::request( )?
Hi,
I'm still struggling with trying to understand how Mod_Perl 2 works. All I want to do is to have a regular Perl script run under Mod_Perl just to speed it up.
In the past, in Mod_Perl 1 I've used this:
sub PrintHeader
{
if ($ENV{'PERL_SEND_HEADER'})
{
print "Content-type: text/html\r\n\r\n";
}
else
{
my $r = Apache->request;
$r->content_type('text/html');
$r->send_http_header;
}
}
I then read the documentation where it says:
Apache->request has been replaced with Apache2::RequestUtil::request( ).
There is also some other documentation in that section that I don't quite understand. In testing and messing around with this in Mod_Perl 2 I've noticed that the simple
print "Content-type: text/html\r\n\r\n";
just works. My Apache configuration looks like this:
<Directory C:\Apache2\Apache2\htdocs\develop>
Options ExecCGI
AddHandler cgi-script .pl
AddHandler cgi-script .cgi
#For ModPerl Only
<IfModule mod_perl.c>
<Files ~ (\.pl)>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlOptions +ParseHeaders
</Files>
</IfModule>
</Directory>
I'm thrilled if:
print "Content-type: text/html\r\n\r\n";
just works. But I want to make sure I understand it and that it is OK before releasing this.
I'm just using ModPerl::Registry to speed regular Perl CGI scripts up. The code needs to work with regular CGI, Mod_Perl 1, Mod_Perl 1.99, and Mod_Perl 2.
And by the way $ENV{'PERL_SEND_HEADER'} does not seem to exist any more. Is this not available in Mod_Perl 2?
How do detect:
PerlOptions -ParseHeaders?
Thanks for your help,
Justin
RE: Do I need Apache2::RequestUtil::request( )?
Posted by Justin Luster <ju...@sawtoothsoftware.com>.
Thank you.
That is what I was hoping to hear.
Thanks,
Justin
-----Original Message-----
From: Tom Schindl [mailto:tomAtLinux@gmx.at]
Sent: Friday, September 16, 2005 12:06 AM
To: Justin Luster
Cc: 'mod_perl List'
Subject: Re: Do I need Apache2::RequestUtil::request( )?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Justin Luster wrote:
> Thanks for your reply.
>
> But why get into all of this confusion when:
>
> print "Content-type: text/html\r\n\r\n"
>
> just works?
>
> Why would I want to use:
>
> $request = Apache2::RequestUtil->request();
>
If the only reason you need $request to print the content-type you don't
need it.
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iD8DBQFDKm7IkVPeOFLgZFIRAqLyAJ9V78A9aq+QLZAM+ETF96Codi+OJQCfZEFH
7jfc845yQM2voY+o7fPGKcM=
=yxu4
-----END PGP SIGNATURE-----
Re: Do I need Apache2::RequestUtil::request( )?
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Justin Luster wrote:
> Thanks for your reply.
>
> But why get into all of this confusion when:
>
> print "Content-type: text/html\r\n\r\n"
>
> just works?
>
> Why would I want to use:
>
> $request = Apache2::RequestUtil->request();
>
If the only reason you need $request to print the content-type you don't
need it.
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iD8DBQFDKm7IkVPeOFLgZFIRAqLyAJ9V78A9aq+QLZAM+ETF96Codi+OJQCfZEFH
7jfc845yQM2voY+o7fPGKcM=
=yxu4
-----END PGP SIGNATURE-----
RE: Do I need Apache2::RequestUtil::request( )?
Posted by Justin Luster <ju...@sawtoothsoftware.com>.
Thanks for your reply.
But why get into all of this confusion when:
print "Content-type: text/html\r\n\r\n"
just works?
Why would I want to use:
$request = Apache2::RequestUtil->request();
-----Original Message-----
From: Tom Schindl [mailto:tomAtLinux@gmx.at]
Sent: Thursday, September 15, 2005 12:29 AM
To: Justin Luster
Cc: 'mod_perl List'
Subject: Re: Do I need Apache2::RequestUtil::request( )?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Justin,
I try to answer you questions step by step:
1. Why does print "Content-type: text/html\r\n\r\n" work?
Because $r->content_type("text/html") does the same behind the scences
2. Should I use Apache2::RequestUtil->request():
This is only available as of mp-2.0.0 and not mp1.99 so you could not
use it earlier than mp-2.0.0.
3. How can I run scripts under mp1, mp1.99, mp2
- -------------------8<--------------------------
my $MOD_PERL;
if (exists $ENV{MOD_PERL}) {
if (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION}
== 2) {
$MOD_PERL = 2;
} else {
## maybe there is a %ENV-Var to use but I can not recover how
## it's named
eval "require mod_perl";
if( defined $mod_perl::VERSION ) {
if ($mod_perl::VERSION >= 1.99) {
$MOD_PERL = 1.99;
} else {
$MOD_PERL = 1;
}
}
}
}
my $request;
if( $MOD_PERL == 2 ) {
$request = Apache2::RequestUtil->request();
} elsif( $MOD_PERL == 1.99 ) {
$request = Apache->request();
} else {
$request = Apache->request();
}
- -------------------8<-------------------
The problem you may want to face is that you need a pre-2.0.0
documentation because functions and their arguments may have changed so
maybe need the mp2-mp1.99-mp1-switch also in your code.
Tom
Justin Luster wrote:
> Hi,
>
>
>
> I'm still struggling with trying to understand how Mod_Perl 2 works.
> All I want to do is to have a regular Perl script run under Mod_Perl
> just to speed it up.
>
>
>
> In the past, in Mod_Perl 1 I?ve used this:
>
>
>
> sub PrintHeader
>
> {
>
> if ($ENV{'PERL_SEND_HEADER'})
>
> {
>
> print "Content-type: text/html\r\n\r\n";
>
> }
>
> else
>
> {
>
> my $r = Apache->request;
>
> $r->content_type('text/html');
>
> $r->send_http_header;
>
> }
>
> }
>
>
>
> I then read the documentation where it says:
>
>
>
> Apache->request has been replaced with Apache2::RequestUtil::request(
).
>
>
>
> There is also some other documentation in that section that I don?t
> quite understand. In testing and messing around with this in Mod_Perl
2
> I?ve noticed that the simple
>
>
>
> print "Content-type: text/html\r\n\r\n";
>
>
>
> just works. My Apache configuration looks like this:
>
>
>
> <Directory C:\Apache2\Apache2\htdocs\develop>
>
> Options ExecCGI
>
> AddHandler cgi-script .pl
>
> AddHandler cgi-script .cgi
>
>
>
> #For ModPerl Only
>
> <IfModule mod_perl.c>
>
> <Files ~ (\.pl)>
>
> SetHandler perl-script
>
> PerlResponseHandler ModPerl::Registry
>
> Options ExecCGI
>
> allow from all
>
> PerlOptions +ParseHeaders
>
> </Files>
>
> </IfModule>
>
> </Directory>
>
>
>
> I?m thrilled if:
>
>
>
> print "Content-type: text/html\r\n\r\n";
>
>
>
> just works. But I want to make sure I understand it and that it is OK
> before releasing this.
>
>
>
> I?m just using ModPerl::Registry to speed regular Perl CGI scripts up.
> The code needs to work with regular CGI, Mod_Perl 1, Mod_Perl 1.99,
and
> Mod_Perl 2.
>
>
>
> And by the way $ENV{'PERL_SEND_HEADER'} does not seem to exist any
> more. Is this not available in Mod_Perl 2?
>
> How do detect:
>
>
>
> PerlOptions -ParseHeaders?
>
>
>
> Thanks for your help,
>
>
>
> Justin
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iD8DBQFDKSKokVPeOFLgZFIRAi8sAKCoW1s2Ds2kWYvrMDQWlu5pdekYYACeOBa4
tN0ebd2NBiGX2KJ7UEQa8Jc=
=jUT+
-----END PGP SIGNATURE-----
Re: Do I need Apache2::RequestUtil::request( )?
Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Justin,
I try to answer you questions step by step:
1. Why does print "Content-type: text/html\r\n\r\n" work?
Because $r->content_type("text/html") does the same behind the scences
2. Should I use Apache2::RequestUtil->request():
This is only available as of mp-2.0.0 and not mp1.99 so you could not
use it earlier than mp-2.0.0.
3. How can I run scripts under mp1, mp1.99, mp2
- -------------------8<--------------------------
my $MOD_PERL;
if (exists $ENV{MOD_PERL}) {
if (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION}
== 2) {
$MOD_PERL = 2;
} else {
## maybe there is a %ENV-Var to use but I can not recover how
## it's named
eval "require mod_perl";
if( defined $mod_perl::VERSION ) {
if ($mod_perl::VERSION >= 1.99) {
$MOD_PERL = 1.99;
} else {
$MOD_PERL = 1;
}
}
}
}
my $request;
if( $MOD_PERL == 2 ) {
$request = Apache2::RequestUtil->request();
} elsif( $MOD_PERL == 1.99 ) {
$request = Apache->request();
} else {
$request = Apache->request();
}
- -------------------8<-------------------
The problem you may want to face is that you need a pre-2.0.0
documentation because functions and their arguments may have changed so
maybe need the mp2-mp1.99-mp1-switch also in your code.
Tom
Justin Luster wrote:
> Hi,
>
>
>
> I'm still struggling with trying to understand how Mod_Perl 2 works.
> All I want to do is to have a regular Perl script run under Mod_Perl
> just to speed it up.
>
>
>
> In the past, in Mod_Perl 1 I?ve used this:
>
>
>
> sub PrintHeader
>
> {
>
> if ($ENV{'PERL_SEND_HEADER'})
>
> {
>
> print "Content-type: text/html\r\n\r\n";
>
> }
>
> else
>
> {
>
> my $r = Apache->request;
>
> $r->content_type('text/html');
>
> $r->send_http_header;
>
> }
>
> }
>
>
>
> I then read the documentation where it says:
>
>
>
> Apache->request has been replaced with Apache2::RequestUtil::request( ).
>
>
>
> There is also some other documentation in that section that I don?t
> quite understand. In testing and messing around with this in Mod_Perl 2
> I?ve noticed that the simple
>
>
>
> print "Content-type: text/html\r\n\r\n";
>
>
>
> just works. My Apache configuration looks like this:
>
>
>
> <Directory C:\Apache2\Apache2\htdocs\develop>
>
> Options ExecCGI
>
> AddHandler cgi-script .pl
>
> AddHandler cgi-script .cgi
>
>
>
> #For ModPerl Only
>
> <IfModule mod_perl.c>
>
> <Files ~ (\.pl)>
>
> SetHandler perl-script
>
> PerlResponseHandler ModPerl::Registry
>
> Options ExecCGI
>
> allow from all
>
> PerlOptions +ParseHeaders
>
> </Files>
>
> </IfModule>
>
> </Directory>
>
>
>
> I?m thrilled if:
>
>
>
> print "Content-type: text/html\r\n\r\n";
>
>
>
> just works. But I want to make sure I understand it and that it is OK
> before releasing this.
>
>
>
> I?m just using ModPerl::Registry to speed regular Perl CGI scripts up.
> The code needs to work with regular CGI, Mod_Perl 1, Mod_Perl 1.99, and
> Mod_Perl 2.
>
>
>
> And by the way $ENV{'PERL_SEND_HEADER'} does not seem to exist any
> more. Is this not available in Mod_Perl 2?
>
> How do detect:
>
>
>
> PerlOptions -ParseHeaders?
>
>
>
> Thanks for your help,
>
>
>
> Justin
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org
iD8DBQFDKSKokVPeOFLgZFIRAi8sAKCoW1s2Ds2kWYvrMDQWlu5pdekYYACeOBa4
tN0ebd2NBiGX2KJ7UEQa8Jc=
=jUT+
-----END PGP SIGNATURE-----