perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philip M. Gollucci" <pgollu...@p6m7g8.com>
Subject Re: redirect doesn't work in eval
Date Tue, 09 Aug 2005 03:43:27 GMT
Marc Lambrichs wrote:
> When a request is sent to the webserver, it handles some stuff and then 
> - sometimes - a redirect must take place. Now the weird part:
> 
> when i use
> $r->headers_out->set( Location => 'http://www.mysite.com/' );
> return Apache2::Const::REDIRECT
> inside an eval{} construction it doesn't work. Is there any logic to this?


Works for me: (Did I misunderstand?)

You can see this in action at
http://p6m7g8.net/redirect
and
http://p6m7g8.net/redirect_with_eval

<Location /redirect>
     SetHandler modperl
     PerlResponseHandler TEST::Redirect
</Location>

<Location /redirect_with_eval>
     SetHandler modperl
     PerlResponseHandler TEST::RedirectE
</Location>

package TEST::Redirect;

use strict;
use warnings FATAL => 'all';
use Carp;

use Apache2::Request ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(REDIRECT);

sub handler {

         my $r = shift;

         $r->headers_out->set(Location => 'http://google.com');
         return Apache2::Const::REDIRECT;
}

1;

package TEST::RedirectE;

use strict;
use warnings FATAL => 'all';
use Carp;

use Apache2::Request ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(REDIRECT);

sub handler {

         my $r = shift;

         eval {
                 $r->headers_out->set(Location => 'http://yahoo.com');
                 return Apache2::Const::REDIRECT;
         }
}

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Mime
View raw message