Rob Bloodgood wrote:
Friday, July 16, 2004, 5:31:35 PM, you wrote:

SB> Ah, sorry, I'm lost in the sea of methods

hahaha I know the feeling.

SB> -- I think we have exactly
SB> what you want. It should appear in here:
SB> http://perl.apache.org/docs/2.0/api/Apache/HookRun.html

This was the key I needed. I installed my module as a HeaderParser
handler (because when I installed it as an Access handler, it recursed
on itself!):

Excellent! Rob, would you like to write a new POD section that can be added to the docs, including your code? It should certainly be linked from the above URL, but I'm not sure what's the best place to put it in. I think
a new section at:
http://perl.apache.org/docs/2.0/user/handlers/http.html
is a good fit.


===
package CTT::302;

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

# comment this out when we're done fixing it.
use Apache::Reload;

btw, it's easier to control that from your httpd.conf w/o having a risk of forgetting to remove this from the code, just add:


PerlModule Apache::Reload
PerlInitHandler Apache::Reload
PerlSetVar ReloadAll Off
PerlSetVar ReloadModules "CTT::302"

or even

PerlSetVar ReloadModules "CTT::*"


use strict;
use warnings;

my $url = "http://www.yahoo.com";;

sub handler {
    my $r = shift;

    my $rc = $r->run_access_checker();
    if ($rc != Apache::OK and $rc != Apache::DECLINED) {
        $r->headers_out->set(Location => $url);
        $rc = Apache::REDIRECT if $rc == Apache::FORBIDDEN;
        return $rc;
    }

    return Apache::DECLINED;
}

1;
===

Now my only remaining question becomes, does the access_checker (eg
mod_access) now run twice, if I *don't* see a FORBIDDEN response? Even
if it does, this still does what I want. :-)

I think the normal access checker phase is always run (if the previous phases didn't abort the HTTP cycle) assuming that you've configured some access handlers to run.


Since the access checker is of type RUN_ALL
http://perl.apache.org/docs/2.0/user/handlers/intro.html#C_RUN_ALL_
you can't prevent any other registered handlers from running. But if there are all Perl handlers, you can unset them:


  $r->set_handlers(PerlAccessHandler => undef)

for the current request.

If the phase was of type RUN_FIRST:
http://perl.apache.org/docs/2.0/user/handlers/intro.html#C_RUN_FIRST_
like authen and authz phases:
http://perl.apache.org/docs/2.0/user/handlers/intro.html#Stacked_Handlers
You could prevent from any handlers from being run, by calling in one phase before the wanted one or earlier (e.g. in access handler to prevent authen handler from running):


  $r->set_handlers(PerlAuthenHandler => \&Apache::OK;)


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

--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Reply via email to