You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Martin Moss <ma...@btopenworld.com> on 2005/08/31 18:06:39 UTC

Multiple Handlers

All,

I'm trying to make something work in mod perl, and all
the docs seem to be pointing me in ways which just
don't work on our system...

Server version: Apache/1.3.33 (Unix)
SunOS 5.9
perl, v5.8.6

I wish to have a handler which sits after the
Authentication stage, which can choose whether to
display a HTML page instead of the originally
requested page.. 
The originally requested page will usually be served
via Embperl, or a method handler..

I originally tried using $r->set_handlers. in my
PerlAuthenHandler. But this made absolutely no
difference to the current request... 
e.g. if did a get_handlers call before and after using
set_handlers, it clearly showed me the handlers I'd
set using set_handlers, but apache ignored this and
carried on serving it's original get_handlers()
anyway.. 

I found many different people reporting bugs in the
set_handlers mechanism and push_handler (which worked
but couldn't help me as what I wanted to do was
unshift (not push) the handlers).

So I tried defining two handlers for the same request,
the first one my custom handler, the second one
Embperl as normal. Now when my custom handler returns
DECLINE the page requested displays
normally.GREAT:-)... 

But when my custom handler actually serves a page, and
returns OK, I actually see the custom handler page
being served, and then the original requested page
appears below with a load of headers and server error
messages....  So basically BOTH handlers are being
called....

Now, I was under the impression (but could be wrong)
that if 2 content PerlHandlers are defined for a
request, then if the first one returns OK then the
second handler doesn't get called, but if it returns
DECLINED then the second one gets called...

Can anybody throw some light on this? 
Why doesn't set_handlers (used in the
PerlAuthenHandler phase) allow me to define the
PerlHandler for the content phase?

How do I prevent other handlers (independant of my
custom handler) from being run if my Custom handler
decides to serve a page...

Kind regards

Marty





	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

Re: Multiple Handlers

Posted by Martin Moss <ma...@btopenworld.com>.
It doesn't seem to work... This was the original
solution I tried..

Here is the code:-

if (Apache->can('set_handlers'))
    {
        print STDERR "CAN PUSH HANDLERS OK\n";
    }
    else
    {
        print STDERR "CANNOT PUSH HANDLERS OK\n";
    }
    my $list = $r->get_handlers( 'PerlHandler' );
    print STDERR "================================\n";
    print STDERR Dumper($$,$0,$list);
    print STDERR "===========================\n";
 $r->set_handlers( 'PerlHandler' =>
['My::Apache::User::Notification']);
 $r->handler('perl-script');
my $list2 = Apache->get_handlers( 'PerlHandler' );
    print STDERR Dumper($$,$list,$list2);
    print STDERR "==========================\n";



Here is the output I get in my logs:-

CAN PUSH HANDLERS OK
==========================================================
$VAR1 = 15253;
$VAR2 = '/www/common/conf/core/traps.conf';
$VAR3 = [
          'Embperl::handler'
        ];
==========================================================
$VAR1 = 15253;
$VAR2 = [
          'Embperl::handler'
        ];
$VAR3 = [
          'III::Apache::User::Notification'
        ];
==========================================================

==========
15253 Apache::AuthenDBI request type = main

In Embperl::handler

So as you can see, the set_handlers seems to work...
But after the Authen stage has returned OK, the next
handler to take control is Embperl::handler...

Any Ideas?

Regards

Marty

--- Geoffrey Young <ge...@modperlcookbook.org> wrote:

> 
> 
> Martin Moss wrote:
> > Have an awful suspicion the book I used suggested
> > doing it the other way around? Would that make a
> > difference?
> > 
> > $r->handler('perl-script');
> > $r->set_handlers(PerlHandler => [ My::Handler ]);
> 
> none whatsoever.
> 
> keep in mind that you can only call set_handlers()
> during phases prior to
> the phase you're setting.  for example, you can't
> 
>   $r->set_handlers(PerlHandler => [ My::Handler ]
> 
> from within a PerlHandler, but you could from within
> a PerlAuthenHandler.
> 
> btw, I saw that you wanted to unshift handlers (as
> opposed to push). this is
> how you do that
> 
>   my $handlers =
> $r->get_handlers(`PerlFixupHandler');
>   $r->set_handlers(PerlFixupHandler => [`My::Bow',
> @$handlers]);
> 
> HTH
> 
> --Geoff
> 



	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

Re: Multiple Handlers

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Martin Moss wrote:
> Have an awful suspicion the book I used suggested
> doing it the other way around? Would that make a
> difference?
> 
> $r->handler('perl-script');
> $r->set_handlers(PerlHandler => [ My::Handler ]);

none whatsoever.

keep in mind that you can only call set_handlers() during phases prior to
the phase you're setting.  for example, you can't

  $r->set_handlers(PerlHandler => [ My::Handler ]

from within a PerlHandler, but you could from within a PerlAuthenHandler.

btw, I saw that you wanted to unshift handlers (as opposed to push). this is
how you do that

  my $handlers = $r->get_handlers(`PerlFixupHandler');
  $r->set_handlers(PerlFixupHandler => [`My::Bow', @$handlers]);

HTH

--Geoff

Re: Multiple Handlers

Posted by Martin Moss <ma...@btopenworld.com>.
Have an awful suspicion the book I used suggested
doing it the other way around? Would that make a
difference?

$r->handler('perl-script');
$r->set_handlers(PerlHandler => [ My::Handler ]);

Marty


--- Geoffrey Young <ge...@modperlcookbook.org> wrote:

> 
> 
> > I originally tried using $r->set_handlers. in my
> > PerlAuthenHandler. But this made absolutely no
> > difference to the current request... 
> 
> if you want to set_handlers() for the PerlHandler
> phase you need two calls
> 
>   $r->set_handlers(PerlHandler => [ My::Handler ]);
>   $r->handler('perl-script');
> 
> HTH
> 
> --Geoff
> 



		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

Re: Multiple Handlers

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

> I originally tried using $r->set_handlers. in my
> PerlAuthenHandler. But this made absolutely no
> difference to the current request... 

if you want to set_handlers() for the PerlHandler phase you need two calls

  $r->set_handlers(PerlHandler => [ My::Handler ]);
  $r->handler('perl-script');

HTH

--Geoff