You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jamie Krasnoo <kr...@socal.rr.com> on 2003/07/21 11:21:07 UTC

MP2 Redirection

What would be the best way to redirect in MP2? How would I set the
Location in the header?

something like this?

my $r = Apache->request;
# docs say $r->header_out and family are now deceased.
$r->headers_out(Location => '/some/place.html');
return Apache::DECLINED;

Jamie Krasnoo


Re: MP2 Redirection

Posted by Stas Bekman <st...@stason.org>.
Jamie Krasnoo wrote:
[...]
>>>>$r->headers_out(Location => '/some/place.html');
>>>>return Apache::DECLINED;
>>>
>>>why DECLINED? just return Apache::OK.
>>
>>My mistake, its been a while and I'm just getting back into it. So its
>>like I'm learning everything all over again. You can use OK? The example
>>in the Eagle book uses REDIRECT within a handler for redirection. So I'm
>>assuming it goes the same for MP2.

You are right, one returns OK if using parsed headers, as in this example:

sub handler {
     my $r = shift;

     my $location = $r->args;

     print "Location: $location\n\n";

     Apache::OK;
}

> I got the redirection to work. However I don't think its working as it
> should. Nowhere in the docs does it say that you have to load APR::Table
> with Apache::RequestRec and Apache::RequestIO to have $r->headers_out()
> to work. Without APR::Table loaded I get the error:
> 
> [Tue Jul 22 03:56:35 2003] [error] [client 192.168.0.2] Can't locate
> object method "STORE" via package "APR::Table" at
> /www/web/perl/MyApache/Redirect.pm line 17.

$r->headers_out returns a tied hash reference, so ones needs to load 
APR::Table in order to work with this reference. Doc patches are very welcome.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: MP2 Redirection

Posted by Jamie Krasnoo <kr...@socal.rr.com>.
On Tue, 2003-07-22 at 03:10, Jamie Krasnoo wrote:
> On Tue, 2003-07-22 at 02:50, Stas Bekman wrote:
> > Jamie Krasnoo wrote:
> > > What would be the best way to redirect in MP2? How would I set the
> > > Location in the header?
> > 
> > not any different from mp1 (assuming that you have been working with mp1 
> > before, but the mp1 documentation and literature can be used as a reference 
> > for most mp2 things).
> > 
> > > something like this?
> > > 
> > > my $r = Apache->request;
> > > # docs say $r->header_out and family are now deceased.
> > 
> > that's right. And $r->headers_out() is available in mp1 for several years and 
> > should be used in mp1 as well to easy the transition.
> > 
> > > $r->headers_out(Location => '/some/place.html');
> > > return Apache::DECLINED;
> > 
> > why DECLINED? just return Apache::OK.
> 
> My mistake, its been a while and I'm just getting back into it. So its
> like I'm learning everything all over again. You can use OK? The example
> in the Eagle book uses REDIRECT within a handler for redirection. So I'm
> assuming it goes the same for MP2.
>  
> > 
> > I'm also not sure why do you use Apache->request, I assume you are inside a 
> > handler, not a registry script. Since if you are inside a registry script you 
> > don't need to return anything at all.
> 
> I was using Apache->request as an example. I guess it's a poor one. I
> should have just used 'my $r = shift;' to get the point across.

I got the redirection to work. However I don't think its working as it
should. Nowhere in the docs does it say that you have to load APR::Table
with Apache::RequestRec and Apache::RequestIO to have $r->headers_out()
to work. Without APR::Table loaded I get the error:

[Tue Jul 22 03:56:35 2003] [error] [client 192.168.0.2] Can't locate
object method "STORE" via package "APR::Table" at
/www/web/perl/MyApache/Redirect.pm line 17.

Place APR::Table in and the error goes away. Here's a sample script
below.


Jamie Krasnoo


package MyApache::Redirect;

use strict;
use warnings;

use Apache::RequestRec;
use Apache::RequestIO;
# comment out 'use APR::Table;' to get error, uncomment to make it go
# away.
# use APR::Table;

use Apache::Const -compile => qw(REDIRECT);

sub handler {
    my $r = shift;

    $r->content_type('text/html');
    $r->headers_out->{Location} = 'http://www.yahoo.com/';

    return Apache::REDIRECT;
}

1;



Re: MP2 Redirection

Posted by Jamie Krasnoo <kr...@socal.rr.com>.
On Tue, 2003-07-22 at 02:50, Stas Bekman wrote:
> Jamie Krasnoo wrote:
> > What would be the best way to redirect in MP2? How would I set the
> > Location in the header?
> 
> not any different from mp1 (assuming that you have been working with mp1 
> before, but the mp1 documentation and literature can be used as a reference 
> for most mp2 things).
> 
> > something like this?
> > 
> > my $r = Apache->request;
> > # docs say $r->header_out and family are now deceased.
> 
> that's right. And $r->headers_out() is available in mp1 for several years and 
> should be used in mp1 as well to easy the transition.
> 
> > $r->headers_out(Location => '/some/place.html');
> > return Apache::DECLINED;
> 
> why DECLINED? just return Apache::OK.

My mistake, its been a while and I'm just getting back into it. So its
like I'm learning everything all over again. You can use OK? The example
in the Eagle book uses REDIRECT within a handler for redirection. So I'm
assuming it goes the same for MP2.
 
> 
> I'm also not sure why do you use Apache->request, I assume you are inside a 
> handler, not a registry script. Since if you are inside a registry script you 
> don't need to return anything at all.

I was using Apache->request as an example. I guess it's a poor one. I
should have just used 'my $r = shift;' to get the point across.

Jamie Krasnoo
 


Re: MP2 Redirection

Posted by Stas Bekman <st...@stason.org>.
Jamie Krasnoo wrote:
> What would be the best way to redirect in MP2? How would I set the
> Location in the header?

not any different from mp1 (assuming that you have been working with mp1 
before, but the mp1 documentation and literature can be used as a reference 
for most mp2 things).

> something like this?
> 
> my $r = Apache->request;
> # docs say $r->header_out and family are now deceased.

that's right. And $r->headers_out() is available in mp1 for several years and 
should be used in mp1 as well to easy the transition.

> $r->headers_out(Location => '/some/place.html');
> return Apache::DECLINED;

why DECLINED? just return Apache::OK.

I'm also not sure why do you use Apache->request, I assume you are inside a 
handler, not a registry script. Since if you are inside a registry script you 
don't need to return anything at all.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com