You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Shevek <sh...@anarres.org> on 2000/12/24 22:10:37 UTC

Apache::Request and redirects

I'm not on the list so please CC me on any replies.

It seems that using Apache::Request and $r->internal_redirect is not a
good idea. The code fragment:

    119     my $mstatus = $mh->handle_request($r);
    120     if ($mstatus != HTTP_OK) {
    121         my $filename = $r->filename;
    122         $filename =~ s,^(.*)/.*$,$1/error.html,;
    123         print STDERR "Redirecting to $filename\n";
    124         my $rstatus = $r->internal_redirect_handler($filename);
    125         print STDERR "Internal redirect done\n";
    126         return $rstatus;

The request object creates itself as undefined data the second time
around, and the web server does not succeed in the redirect. Even though I
have passed my Anarres::Request (inheriting Apache::Request) to the
internal_redirect method, Apache creates a new Apache object and uses that
in the subrequest.

I want the parameters from the first request to be preserved into the
subrequest.

Another minor issue is that Apache::Request is not trivially subclassed,
the returned value from $self->SUPER::new() must be reblessed into the
desired class.

S.

--
Shevek
I am the Borg.
sub AUTOLOAD { ($s=$AUTOLOAD)=~s/.*:://; eval qq{ *$AUTOLOAD=$s
?sub {$s*&{$s-1}} :sub {1}; }; goto &$AUTOLOAD; } print &{'4'}; 


Re: Apache::Request and redirects

Posted by Dave Rolsky <au...@urth.org>.
On Sat, 30 Dec 2000, Matt Sergeant wrote:

> > Another minor issue is that Apache::Request is not trivially subclassed,
> > the returned value from $self->SUPER::new() must be reblessed into the
> > desired class.
>
> Thats a pretty standard perl idiom:
>
> sub new {
>   my $class = shift;
>   my $self = $class->SUPER::new;
>   bless $self, $class;
> }

Well, a package is generally expected to bless its objects into the value
of $class, not the value of __PACKAGE__.  You shouldn't have to override
the constructor simply to rebless the object.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/


Re: Apache::Request and redirects

Posted by Matt Sergeant <ma...@sergeant.org>.
On Sun, 24 Dec 2000, Shevek wrote:

> I want the parameters from the first request to be preserved into the
> subrequest.

Store in a global variable then:

$MyPackage::request = $apr;

Then access in the internal redirect.

> Another minor issue is that Apache::Request is not trivially subclassed,
> the returned value from $self->SUPER::new() must be reblessed into the
> desired class.

Thats a pretty standard perl idiom:

sub new {
  my $class = shift;
  my $self = $class->SUPER::new;
  bless $self, $class;
}

-- 
<Matt/>

    /||    ** Director and CTO **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // **     Personal Web Site: http://sergeant.org/     **
     \\//
     //\\
    //  \\