libapa...ookRun(3pm)
π libapa...ookRun(3pm) β from the User Contributed Perl Documentation collection, bestie. This is part 1 of 2, so buckle up π«Ά
β¨ NAME β¨
Apache2::HookRun β the Perl API for invoking Apache HTTP phases π
πΈ Synopsis πΈ
okay so first, the vibe. In your httpd.conf:
# 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;
}
that's the whole HTTP request cycle, hand-rolled, in like 60 lines. iconic honestly π₯
π¦ Description π¦
Apache2::HookRun exposes parts of the Apache HTTP protocol implementation β specifically the bits responsible for invoking callbacks for each HTTP Request cycle phase. it's giving "backstage pass to the request lifecycle" π
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 a command server, which has nothing to do with HTTP. Also, real talk, the Synopsis up there shows you how to re-implement the entire Apache HTTP cycle inside a protocol handler. no cap β¨
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. straight up: if you just try to use the methods from this module without understanding them well, don't be surprised if you get some nasty crashes, from which mod_perl can't protect you.
π bestie. NASTY CRASHES. mod_perl literally cannot save you from those. read the C code first, i'm begging π
π API π
Apache2::HookRun provides the following functions and/or methods:
π die
Kill the current request πͺ¦
$r->die($type);
- obj:
$r(Apache2::RequestRecobject ) β the current request - arg1:
$type( integer ) β why the request is dieing. expects an Apache status constant. - ret: no return value
- since: 2.0.00
This method doesn't really abort the request β it just handles the sending of the error response, logging the error and such. if you wanna see the internals, go look at ap_die() in httpd-2.0/modules/http/http_request.c for more details. iykyk π
π invoke_handler
Run the response phase. the main character phase fr π
$rc = $r->invoke_handler();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::HTTP_... - since: 2.0.00
invoke_handler() allows modules to insert filters, sets a default handler if none is set, runs run_handler() and handles some errors. it does the whole little routine π
For more details see ap_invoke_handler() in httpd-2.0/server/config.c.
π run_access_checker
Run the resource access control phase. πͺ
$rc = $r->run_access_checker();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This phase runs before a user is authenticated, so this hook is really there to apply additional restrictions independent of a user. It also runs independent of the "Require" directive usage. so like, no auth needed to gatekeep you here π«Ά
πΈ run_auth_checker
Run the authentication phase. π
$rc = $r->run_auth_checker();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This phase is used to check to see if the resource being requested is available for the authenticated user ($r->user and $r->ap_auth_type).
It runs after the access_checker and check_user_id hooks.
Note that it will only be called if Apache determines that access control has been applied to this resource (through a "Require" directive). no Require, no check, periodt β
π§ run_check_user_id
Run the authorization phase. π«
$rc = $r->run_check_user_id();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This hook is used to analyze the request headers, authenticate the user, and set the user information in the request record ($r->user and $r->ap_auth_type).
This hook is only run when Apache determines that authentication/authorization is required for this resource (as determined by the "Require" directive). again β only if Require said so π
It runs after the access_checker hook, and before the auth_checker hook. order matters bestie π¦
β run_fixups
Run the fixup phase. π οΈ
$rc = $r->run_fixups();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This phase allows modules to perform module-specific fixing of HTTP header fields. It's invoked just before the response phase. last-minute glow-up before the main event β¨
π run_handler
Run the response phase. π¬
$rc = $r->run_handler();
- obj:
$r(Apache2::RequestRecobject ) β therequest_rec - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
run_handler() is called internally by invoke_handler(). Use run_handler() only if you want to bypass the extra functionality provided by invoke_handler(). it's giving "i know what i'm doing" energy π
π run_header_parser
Run the header parser phase. π¨
$rc = $r->run_header_parser();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) βApache2::Const::OKorApache2::Const::DECLINED - since: 2.0.00
π run_log_transaction
Run the logging phase. π
$rc = $r->run_log_transaction();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This hook allows modules to perform any module-specific logging activities over and above the normal server things. journal entry time π«Ά
π¦ run_map_to_storage
Run the map_to_storage phase. πΊοΈ
$rc = $r->run_map_to_storage();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) βApache2::Const::DONE(orApache2::HTTP_*) if this contextless request was just fulfilled (such asTRACE),Apache2::Const::OKif this is not a file, andApache2::Const::DECLINEDif this is a file. The coremap_to_storage(Apache2::HOOK_RUN_LAST) willdirectory_walk()andfile_walk()the$r->filename(all internal C functions). - since: 2.0.00
This phase allows modules to set the per_dir_config based on their own context (such as <Proxy> sections) and responds to contextless requests such as TRACE that need no security or filesystem mapping based on the filesystem.
π run_post_read_request
Run the post_read_request phase. π¬
$rc = $r->run_post_read_request();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OKorApache2::Const::DECLINED - since: 2.0.00
This phase is run right after read_request() or internal_redirect(), 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. early bird energy, but not for subrequests bestie π¦
πΈ run_translate_name
Run the translate phase. π€
$rc = $r->run_translate_name();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
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. URI β filename pipeline, slay π
π§ run_type_checker
Run the type_checker phase. π·οΈ
$rc = $r->run_type_checker();
- obj:
$r(Apache2::RequestRecobject ) β the current request - ret:
$rc( integer ) β the status of the current phase run:Apache2::Const::OK,Apache2::Const::DECLINED,Apache2::HTTP_... - since: 2.0.00
This phase is used to determine and/or set the various document type information bits, like Content-type (via $r->content_type), language, etc. the "what even IS this file" phase π
girl, we're not done β part 2 incoming π«Ά
πΈ SEE ALSO πΈ
okay bestie you survived the whole API section (iconic behaviour, genuinely) so here's the one place to send your eyeballs next:
mod_perl 2.0 documentation.β that's the whole homework assignment. go read it. it's giving "everything you just learned, but at scale" π
π COPYRIGHT π
real talk, the legal tea: mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. no cap, that's the license, that's the vibe. read it if you're shipping this stuff anywhere. π«Ά
π AUTHORS π
who do you have to thank for all this? β¨ The mod_perl development team and numerous contributors. β¨
basically a whole group chat of absolute legends, plus a bunch of other people who showed up and cooked. not me getting emotional about a Perl module at 3am ππ
p.s. this page beamed into your terminal from perl v5.42.3, dated 2026-08-20, and its official glow-up name islibapa...ookRun(3pm). stan a manpage that knows its own birthday ππ go forth anduseresponsibly, bestie π¦
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-perl2 2.0.13-2build3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms