CGI.pm and ModPerl::Registry

CGI.pm and ModPerl::Registry

am 22.12.2007 05:20:25 von steve.yost

My site has been humming along in blissful ignorance of the latest
Perl happenings for several years, running Perl 5.6.0, Apache 1.3, and
whatever version of mod_perl was current. I use CGI.pm to do request
parsing and response output, because the whole site used to be
CGI scripts.

I'm in the process of upgrading to Perl 5.8.8, Apache 2.0, and
ModPerl::Registry, and CGI.pm v3.29.
Right now, all the redirects I do that follow POSTs are broken. They
produce status 200 instead of status 303 that I coded for. Any ideas
why or other advice?
Thanks very much.

Here's a stripped down bit of sample code:

my @headerargs = ('-cookie', $my_cookie) if $my_cookie;

my @redirargs =
('-Status', '303 See Other',
'-Location', $forward_url,
'-URL', $forward_url);

push (@headerargs, @redirargs);
print $cgi->header(@headerargs);

# print some text ...

exit();


-Steve

Re: CGI.pm and ModPerl::Registry

am 22.12.2007 08:06:16 von Claudio Calvelli

On 2007-12-22, steve.yost@gmail.com wrote:
> I'm in the process of upgrading to Perl 5.8.8, Apache 2.0, and
> ModPerl::Registry, and CGI.pm v3.29.
> Right now, all the redirects I do that follow POSTs are broken. They
> produce status 200 instead of status 303 that I coded for. Any ideas
> why or other advice?
> Thanks very much.

The CGI.pm documentation suggests to use redirect rather than header
to creating redirections, so something along the lines of:

print $cgi->redirect(-uri=>$otherurl, -status=>303)

should work.

C

--
The address in the "From" header won't work. Email to "usenet" at "intercal" dot
"dyn-o-saur" dot "com" may or may not reach me, depending on how far it manages
to go through the spam filter, and other conditions which I won't disclose.

Re: CGI.pm and ModPerl::Registry

am 22.12.2007 16:47:20 von steve.yost

On Dec 22, 2:06 am, Claudio Calvelli
wrote:
> On 2007-12-22, steve.y...@gmail.com wrote:
>
> > I'm in the process of upgrading to Perl 5.8.8, Apache 2.0, and
> > ModPerl::Registry, and CGI.pm v3.29.
> > Right now, all the redirects I do that follow POSTs are broken. They
> > produce status 200 instead of status 303 that I coded for. Any ideas
> > why or other advice?
> > Thanks very much.
>
> The CGI.pm documentation suggests to use redirect rather than header
> to creating redirections, so something along the lines of:
>
> print $cgi->redirect(-uri=>$otherurl, -status=>303)
>
> should work.
>
> C


Thanks for the reply, Claudio. That didn't help, but I did find that
the problem was resolved by not printing any text after the header.
Apparently with text printed, CGI.pm reverts that status back to 200,
which seems reasonable. If you're redirecting, you shouldn't need any
text, and if you succesfully produce a web page, it's reasonable that
the status be 200.
So the status was coming through as 200 but there was a location in
the http header, which let to the result being a page that said:

OK
The answer to your request is located here

with *here* being a link to the url I was forwarding to.

The text was legacy support for browsers that might not support
forwarding (my service has been around since 1999!).

Hope all this helps anyone else that runs into this problem.

Steve

Re: CGI.pm and ModPerl::Registry

am 22.12.2007 22:08:23 von Claudio Calvelli

On 2007-12-22, steve.yost@gmail.com wrote:
> Thanks for the reply, Claudio. That didn't help, but I did find that
> the problem was resolved by not printing any text after the header.
> Apparently with text printed, CGI.pm reverts that status back to 200,
> which seems reasonable. If you're redirecting, you shouldn't need any
> text, and if you succesfully produce a web page, it's reasonable that
> the status be 200.

It looks like it's mod_perl which does that.

I put the following script both in $DOCUMENTROOT/cgi-bin/test.cgi and
$DOCUMENTROOT/perl/test.cgi:

---- cut here ---- script ----
#!/usr/bin/perl -w
use strict;
use CGI;

my $cgi = new CGI;
my $location = 'http://www.some-otherp-lace.com/';

print $cgi->redirect( -uri => $location, -status => 303);
print "... and if you aren't automatically redirected, see \n";
---- cut here ----

The cgi-bin version works as expected:

----
GET /cgi-bin/test.cgi HTTP/1.0

HTTP/1.1 303 See Other
Date: Sat, 22 Dec 2007 21:02:58 GMT
Server: Apache
Location: http://www.some-otherp-lace.com/
Connection: close
Content-Type: text/plain

.... and if you aren't automatically redirected, see
----

The mod_perl version changes the 303 to 200:

----
GET /perl/test.cgi HTTP/1.0

HTTP/1.1 200 OK
Date: Sat, 22 Dec 2007 21:05:05 GMT
Server: Apache
Location: http://www.some-otherp-lace.com/
Connection: close
Content-Type: text/plain

.... and if you aren't automatically redirected, see


200 OK

OK


The answer to your request is located .



----

Note how the status becomes 200, and a whole new document with the redirect
is added after the text!

C
--
The address in the "From" header won't work. Email to "usenet" at "intercal" dot
"dyn-o-saur" dot "com" may or may not reach me, depending on how far it manages
to go through the spam filter, and other conditions which I won't disclose.

Re: CGI.pm and ModPerl::Registry

am 22.12.2007 23:37:33 von none

On Dec 22, 4:08 pm, Claudio Calvelli
wrote:
> It looks like it's mod_perl which does that.
>

Precisely. Nice test!

Thanks,
Steve