Geoffrey Young wrote:

Arshavir Grigorian wrote:

Hello list,

I am trying to use the stacked handlers functionality but cannot seem to
get it working. What I have is the following 2 modules:

package Test;

use strict;

sub handler {
   my $r = shift;

   $r->push_handlers(PerlResponseHandler => 'Test1::handler');

   return Apache2::Const::OK;
}

1;

package Test1;

use strict;

sub handler {
   my $r = shift;

   $r->content_type('text/html');

   print qq{<html><body><h3>we are here</h3></body></html>\n};

   return Apache2::Const::OK;
}

1;

<Location /test/>
       SetHandler perl-script
       PerlResponseHandler Test
</Location>

I was hoping the request to http://localhost/test/ would eventually be
passed to Test1 and I would see the "we are here" message, but all I get
is an empty screen. Does anyone see any problems with this setup? TIA.


yes, stacked handlers works exactly like what you are doing for every phase
_except_ content generation.  to enable mod_perl for content generation you
need to add

  SetHandler perl-script

someplace, either in your httpd.conf or via a

  $r->handler('perl-script');

at the appropriate place.

HTH

--Geoff

well, I already have a section in httpd.conf for Test1 (similar that for Test), like so:

<Location /test1/>
        SetHandler perl-script
        PerlResponseHandler Test1
</Location>

Is this what you were referring to? Unfortunately, it still does not work.

On a related note, I have a system that consists of an Application module, which receives the requests, checks for authentication, etc and if the user is authenticated/authorized, passes the request on to another module (based on the path_info()) to handle the request. This was fine untill I needed to return a redirect from one of the modules.

package Application;

sub handler {
   my $r = shift;
   ...
   if ($r->path_info() =~ m/app1/) {
      ModuleApp1::handler($r);
   } elsif ($r->path_info() =~ m/app2/) {
      ModuleApp2::handler($r);
   }
   return Apache2::Const::OK;
}

package ModuleApp1;

sub handler {
    my $r = shift;

    if ($some_condition) {
        $r->headers_out->set(Location => '/jobstatus/');
        return Apache2::Const::REDIRECT;
    } else {
        ... process
        return Apache2::Const::OK;
    }
}

I thought that if I used stacked handlers, it would just work. But now I am not so sure that's what I need specifically because ModuleApp1|2 are not configured to handle requests directly forcing the request to go through Application first for authentication/authorization.

I am now thinking of storing all the return values from all the modules then returning it from Application::handler() (or returning Apache2::Const::OK if the return code is not set).
Is this a good approach?

package Application;

sub handler {
   my $r = shift;
   ...
   my $rc;
   if ($r->path_info() =~ m/app1/) {
      $rc = ModuleApp1::handler($r);
   } elsif ($r->path_info() =~ m/app1/) {
      $rc = ModuleApp2::handler($r);
   }
        
   if ($rc) {
        return $rc;
   } else {     
        return Apache2::Const::OK;
   }
}

Thanks in advance for any comments you might have.


--
Arshavir Grigorian
Systems Administrator/Engineer

Reply via email to