Mike Stok <mike@stok.co.uk> wrote:
> I am having an odd problem with a redirect using apacha & mod perl.
>
> #!/usr/local/register/bin/perl -w
>
> use CGI::Switch;
>
> my $q = new CGI::Switch;
>
> $q->print ($q->redirect (-uri => 'http://vrooom.nis.newscorp.com:8008/',
> -nph => 1));
>
> as a "regular" cgi script works OK, but under mod_perl gets a "document
> contains no data" error out of the browser. When under mod_perl I have
> the code in .../register/code/boing ans the httpd.conf file says
[...]
> Is there some simple mistake I'm making? I'm using perl 5.003_95 and
> mod_perl 0.95_02 with apache 1.2b7 ... changing the versions fills me with
> terror as I'm < 24 hours away from a product roll out and the code works
> OK as CGI.
nuts, I should have done something about this a while ago. See, CGI
reads your scripts output, scanning headers and such. mod_perl does
not. This patch should makes things behave as expected.
p5p-msgid:
199704041732.MAA05896@postman.osf.org
private-msgid:
199704051527.KAA11280@postman.osf.org
$url = $url || $self->self_url;
my(@o);
foreach (@other) { push(@o,split("=")); }
- push(@o,
+ if($MOD_PERL or exists $self->{'.req'}) {
+ my $r = $self->{'.req'} || Apache->request;
+ $r->header_out(Location => $url);
+ $r->err_header_out(Location => $url);
+ $r->status(302);
+ return;
+ }
+ else {
+ push(@o,
'-Status'=>'302 Found',
'-Location'=>$url,
- '-URI'=>$url,
- '-nph'=>($nph||$NPH));
+ '-nph'=>($nph||$NPH),
+ );
+ }
+ push(@o, '-URI'=>$url);
push(@o,'-Target'=>$target) if $target;
push(@o,'-Cookie'=>$cookie) if $cookie;
return $self->header(@o);