Full List of Apache Hooks

Published: December 7, 2016

Tags:

Apache’s hooking system provides a very convenient way to customize request processing. However, thorough documentation is difficult to track down. The Apache developer documentation refers readers to the Doxygen documentation, however that page makes no mention of some commonly used hooks such as log_header_size_post_read_request.

After much time scouring the web, by chance, while looking through the Apache source code, I stumbled upon the source code of mod_example_hooks.c. After briefly glancing through the file I quickly realized that I had found the pot of gold at the end of the rainbow that I was looking for.

At the top of the file you’ll see the following line immediately communicating that mod_example_hooks.c is the intended to show how hooks are meant to be used.

It provides demonstrations of how modules do things. It participates in all of the processing phases.

Then you’‘ll see function after function documenting how each hook is intended to be used. For example…

/*
 * This routine is called to perform any module-specific log file
 * openings. It is invoked just before the post_config phase
 *
 * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
 * server will still call any remaining modules with an handler for this
 * phase.
 */
static int x_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
                        apr_pool_t *ptemp, server_rec *s)
{
    /*
     * Log the call and exit.
     */
    trace_startup(ptemp, s, NULL, "x_open_logs()");
    return OK;
}

And then…

/*
 * This routine is called after the server finishes the configuration
 * process.  At this point the module may review and adjust its configuration
 * settings in relation to one another and report any problems.  On restart,
 * this routine will be called only once, in the running server process.
 *
 * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
 * server will still call any remaining modules with an handler for this
 * phase.
 */
static int x_post_config(apr_pool_t *pconf, apr_pool_t *plog,
                          apr_pool_t *ptemp, server_rec *s)
{
    /*
     * Log the call and exit.
     */
    trace_startup(ptemp, s, NULL, "x_post_config()");
    return OK;
}

If you’re trying to understand all the hooks available to you as an Apache module developer, first and foremost, I highly suggest you read through the source code of mod_example_hooks.c. It is, by far, the most thorough documentation of Apache hooks that I was able to find.

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Rightpoint where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.