I am having a _really_ strange problem with return() under mod_perl. It
seems that any time I attempt to do a return REDIRECT after I have accessed
any passed parameters, the redirect will fail. However, if I do the
redirect without accessing any passed parameters (either via POST or GET),
the redirect works fine. I have debugged and debugged, and what I have
found is that if I create a hash of the passed parameters using $r->content,
$r->args, or even looping through with CGI::param, and then try and
redirect, it will fail. The hash does indeed get created (I can loop
through and output the values fine), but the browser will "hang" right when
it tries to execute the return REDIRECT. If I do not create the hash, the
redirect works perfectly. Perhaps some examples would help...:
The following code works great:
#begin code
package my::module;
use strict;
use Apache;
use Apache::Constants qw(:common :response);
use Carp;
sub handler {
my $r = shift;
$r->content_type('text/html');
my $location = 'http://www.anysite.com';
$r->header_out(Location => $location);
return REDIRECT;
}
#end code
The following also works:
#begin code
#assume same header info
sub handler {
my $r = shift;
$r->internal_redirect('/cgi-bin/myscript.pl');
return OK;
}
#end code
But, the strange part is, when I use the following code, the browser spins
and spins and finally just dies when it reaches the return():
#begin code
#assume same header info
sub handler {
my $r = shift;
my %args = $r->content;
# or my %args = $r->args;
# or the following:
# foreach $name (CGI::param()) {
# $args{$name} = CGI::param($name);
# }
$r->content_type('text/html');
my $location = 'http://www.anysite.com';
$r->header_out(Location => $location);
return REDIRECT;
#also dies if using $r->internal_redirect() method
}
#end code
Has anyone seen this before? For some reason, the addition of the line that
takes the POSTed or GETed values and turns them into a hash is killing it. I
have output the contents of the %args hash after it is created, and
everything is in there and fine. But when it hits the redirect after doing
this, it refuses to go anywhere. But the mystery deepens...
I can create a hash "manually" and all still works fine, like so:
#begin code
#assume same header info
sub handler {
my $r = shift;
my %args = ('key1' => 'value1');
$r->content_type('text/html');
my $location = 'http://www.anysite.com';
$r->header_out(Location => $location);
return REDIRECT;
#also now works if using $r->internal_redirect() method
}
#end code
In this example, the redirect still happens without a problem. Why would
accessing passed parameters cause this to happen? Or is something happening
that I am unaware of? Is this a known "bug"? Many of the examples in
_Writing Apache Modules with Perl and C_ call methods on $r before the
redirect happens, and as such the authors note nothing unusual. If it
helps, the web server is Apache 1.3.9 (compiled with mod_perl, obviously) on
Solaris 2.7, and I am browsing this using Netscape from a FreeBSD box. I
have even tried telneting into port 80 on the server and doing a manual HTTP
session. When the return is reached, the telnet session simply locks up, so
it is not a browser issue.
One other important thing to note is that I have been in contact with others
who have been able to reproduce this on entirely different architecture, so
this is not limited to my machines.
This seems so crazy to me, as I am sure others have accessed passes
parameters and then done a redirect. I am certain I am not the first. But
it is very important that I get this working, and I have yet to find any
answers.
Any assistance or insight, as always, is appreciated.
Jason Simms
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com