=head1 NAME Apache2::HookRun - Perl API for Invoking Apache HTTP phases =head1 Synopsis # httpd.conf PerlProcessConnectionHandler MyApache2::PseudoHTTP::handler #file:MyApache2/PseudoHTTP.pm #--------------------------- package MyApache2::PseudoHTTP; use Apache2::HookRun (); use Apache2::RequestUtil (); use Apache2::RequestRec (); use Apache2::Const -compile => qw(OK DECLINED DONE SERVER_ERROR); # implement the HTTP protocol cycle in protocol handler sub handler { my $c = shift; my $r = Apache2::RequestRec->new($c); # register any custom callbacks here, e.g.: # $r->push_handlers(PerlAccessHandler => \&my_access); $rc = $r->run_post_read_request(); return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_translate_name; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_map_to_storage; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; # this must be run all a big havoc will happen in the following # phases $r->location_merge($path); $rc = $r->run_header_parser; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; my $args = $r->args || ''; if ($args eq 'die') { $r->die(Apache2::Const::SERVER_ERROR); return Apache2::Const::DONE; } $rc = $r->run_access_checker; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_auth_checker; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_check_user_id; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_type_checker; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_fixups; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; # $r->run_handler is called internally by $r->invoke_handler, # invoke_handler sets all kind of filters, and does a few other # things but it's possible to call $r->run_handler, bypassing # invoke_handler $rc = $r->invoke_handler; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; $rc = $r->run_log_transaction; return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED; return Apache2::Const::OK; } =head1 Description C exposes parts of the Apache HTTP protocol implementation, responsible for invoking callbacks for each L. Armed with that API, you could run some of the http protocol framework parts when implementing your own protocols. For example see how HTTP AAA (access, auth and authz) hooks are called from a protocol handler, implementing L, which has nothing to do with HTTP. Also you can see in L how to re-implement Apache HTTP cycle in the protocol handler. Using this API you could probably also change the normal Apache behavior (e.g. invoking some hooks earlier than normal, or later), but before doing that you will probably need to spend some time reading through the Apache C code. That's why some of the methods in this document, point you to the specific functions in the Apache source code. If you just try to use the methods from this module, without understanding them well, don't be surprised if you will get some nasty crashes, from which mod_perl can't protect you. =head1 API C provides the following functions and/or methods: =head2 C Kill the current request $r->die($type); =over 4 =item obj: C<$r> ( C> ) The current request =item arg1: C<$type> ( integer ) Why the request is dieing. Expects an Apache status constant. =item ret: no return value =item since: 2.0.00 =back This method doesn't really abort the request, it just handles the sending of the error response, logging the error and such. You want to take a look at the internals of C in F for more details. =head2 C Run the L phase. $rc = $r->invoke_handler(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C =item since: 2.0.00 =back C allows modules to insert filters, sets a default handler if none is set, runs C> and handles some errors. For more details see C in F. =head2 C Run the resource L phase. $rc = $r->run_access_checker(); =over 4 =item obj: C<$r> ( C> ) the current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This phase runs before a user is authenticated, so this hook is really to apply additional restrictions independent of a user. It also runs independent of 'C' directive usage. =head2 C Run the L phase. $rc = $r->run_auth_checker(); =over 4 =item obj: C<$r> ( C> ) the current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This phase is used to check to see if the resource being requested is available for the authenticated user (C<$r-Euser> and C<$r-Eap_auth_type>). It runs after the L and L hooks. Note that it will only be called if Apache determines that access control has been applied to this resource (through a 'C' directive). =head2 C Run the L phase. $rc = $r->run_check_user_id(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This hook is used to analyze the request headers, authenticate the user, and set the user information in the request record (C<$r-Euser> and C<$r-Eap_auth_type>). This hook is only run when Apache determines that authentication/authorization is required for this resource (as determined by the 'C' directive). It runs after the L hook, and before the L hook. =head2 C Run the L phase. $rc = $r->run_fixups(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This phase allows modules to perform module-specific fixing of HTTP header fields. This is invoked just before the L phase. =head2 C Run the L phase. $rc = $r->run_handler(); =over 4 =item obj: C<$r> ( C> ) The request_rec =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back C is called internally by C>. Use C only if you want to bypass the extra functionality provided by C>. =head2 C Run the L
phase. $rc = $r->run_header_parser(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) C or C. =item since: 2.0.00 =back =head2 C Run the L phase. $rc = $r->run_log_transaction(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C =item since: 2.0.00 =back This hook allows modules to perform any module-specific logging activities over and above the normal server things. =head2 C Run the L phase. $rc = $r->run_map_to_storage(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) C (or C) if this contextless request was just fulfilled (such as C), C if this is not a file, and C if this is a file. The core map_to_storage (C) will C and C the C<$r-Efilename> (all internal C functions). =item since: 2.0.00 =back This phase allows modules to set the per_dir_config based on their own context (such as CProxyE> sections) and responds to contextless requests such as C that need no security or filesystem mapping based on the filesystem. =head2 C Run the L phase. $rc = $r->run_post_read_request(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C or C. =item since: 2.0.00 =back This phase is run right after C or C, and not run during any subrequests. This hook allows modules to affect the request immediately after the request has been read, and before any other phases have been processes. This allows modules to make decisions based upon the input header fields =head2 C Run the L phase. $rc = $r->run_translate_name(); =over 4 =item obj: C<$r> ( C> ) The current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This phase gives modules an opportunity to translate the URI into an actual filename. If no modules do anything special, the server's default rules will be applied. =head2 C Run the L phase. $rc = $r->run_type_checker(); =over 4 =item obj: C<$r> ( C> ) the current request =item ret: C<$rc> ( integer ) The status of the current phase run: C, C, C. =item since: 2.0.00 =back This phase is used to determine and/or set the various document type information bits, like C (via C<$r-Econtent_type>), language, etc. =head1 See Also L. =head1 Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. =head1 Authors L. =cut