7.6. Customizing the Fixup Phase

The fixup phase is sandwiched between the type checking phase and the response phase. It gives modules a last-minute chance to add information to the environment or to modify the request record before the content handler is invoked. For instance, the standard mod_usertrack module implements the CookieTracking directive in this phase, adding a user-tracking cookie to the outgoing HTTP headers and recording a copy of the incoming cookie to the notes table for logging purposes.

As an example of a useful Perl-based fixup handler, we'll look at Apache::HttpEquiv, a module written by Rob Hartill and used here with his permission. The idea of Apache::HttpEquiv is simple. The module scans the requested HTML file for any <META> tags containing the HTTP-EQUIV and CONTENT attributes. The information is then added to the outgoing HTTP headers.

For example, if the requested file contains this HTML:

<HTML> 
<HEAD><TITLE>My Page</TITLE> 
<META HTTP-EQUIV="Expires" CONTENT="Wed, 31 Jul 1998 16:40:00 GMT"> 
<META HTTP-EQUIV="Set-Cookie" CONTENT="open=sesame">

the handler will convert the <META> tags into these response headers:

Expires: Wed, 31 Jul 1998 16:40:00 GMT
Set-Cookie: open=sesame

Example 7.7 gives the succinct code for Apache::HttpEquiv. The handler() routine begins by testing the current request for suitability. It returns with a status code of DECLINED if any of the following are true:

  • The request is a subrequest.

  • The requested document's MIME type ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.