handler.html.en revision 1e86aafffa12e58c7cfe4244690eff3b82bd02c4
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<HTML>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<HEAD>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<TITLE>Apache's Handler Use</TITLE>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</HEAD>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<BODY
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes BGCOLOR="#FFFFFF"
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes TEXT="#000000"
0662ed52e814f8f08ef0e09956413a792584eddffuankg LINK="#0000FF"
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes VLINK="#000080"
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes ALINK="#FF0000"
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<!--#include virtual="header.html" -->
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<H1 ALIGN="CENTER">Apache's Handler Use</H1>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<ul>
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes<li><a href="#definition">What is a Handler</a></li>
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes<li><a href="#examples">Examples</a></li>
16b55a35cff91315d261d1baa776138af465c4e4fuankg<li><a href="#programmer">Programmer's Note</a></li>
16b55a35cff91315d261d1baa776138af465c4e4fuankg</ul>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<hr>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<H2><a name="definition">What is a Handler</a></H2>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<table border="1">
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<tr><td valign="top">
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<strong>Related Modules</strong><br><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<a href="mod/mod_actions.html">mod_actions</a><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_asis.html">mod_asis</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_cgi.html">mod_cgi</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_imap.html">mod_imap</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_info.html">mod_info</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_include.html">mod_include</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<a href="mod/mod_mime.html">mod_mime</a><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_negotiation.html">mod_negotiation</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_status.html">mod_status</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</td>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<td valign="top">
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<strong>Related Directives</strong><br><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<a href="mod/mod_actions.html#action">Action</a><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_mime.html#addhandler">AddHandler</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<a href="mod/mod_mime.html#removehandler">RemoveHandler</a><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_mime.html#sethandler">SetHandler</A><br>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</td>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</tr></table>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<P>A "handler" is an internal Apache representation of the action to be
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesperformed when a file is called. Generally, files have implicit
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholeshandlers, based on the file type. Normally, all files are simply
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesserved by the server, but certain file types are "handled"
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesseparately.</P>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg<P>Apache 1.1 adds the ability to use handlers explicitly. Based on
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholeseither filename extensions or on location, handlers can be specified
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholeswithout relation to file type. This is advantageous both because it is
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesa more elegant solution, and because it also allows for both a type
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<STRONG>and</STRONG> a handler to be associated with a file. (See also
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<A HREF="mod/mod_mime.html#multipleext">Files with Multiple
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesExtensions</A>.)</p>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<P>Handlers can either be built into the server or included in a module,
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesor they can be added with the <A
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesHREF="mod/mod_actions.html#action">Action</A> directive. The built-in
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholeshandlers in the standard distribution are as follows:</P>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<UL>
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg<LI><STRONG>default-handler</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Send the file using the <CODE>default_handler()</CODE>, which is the
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes handler used by default to handle static content.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (core)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>send-as-is</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Send file with HTTP headers as is.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_asis.html">mod_asis</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>cgi-script</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Treat the file as a CGI script.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_cgi.html">mod_cgi</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>imap-file</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Parse as an imagemap rule file.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_imap.html">mod_imap</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>server-info</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Get the server's configuration information.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_info.html">mod_info</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>server-parsed</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Parse for server-side includes.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_include.html">mod_include</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>server-status</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Get the server's status report.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_status.html">mod_status</A>)
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<LI><STRONG>type-map</STRONG>:
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Parse as a type map file for content negotiation.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes (<A HREF="mod/mod_negotiation.html">mod_negotiation</A>)
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg</UL>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<hr>
0a39e7683f6611d66c55712f50bb240428d832a1bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<h2><a name="examples">Examples</a></h2>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<h3>Modifying static content using a CGI script</h3>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<p>The following directives will cause requests for files with the
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<code>html</code> extension to trigger the launch of the
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<code>footer.pl</code> CGI script.</p>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg<pre>
0662ed52e814f8f08ef0e09956413a792584eddffuankg Action add-footer /cgi-bin/footer.pl
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes AddHandler add-footer .html
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg</pre>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<p>Then the CGI script is responsible for sending the originally
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesrequested document (pointed to by the <code>PATH_TRANSLATED</code>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesenvironment variable) and making whatever modifications or additions
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesare desired.</p>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<h3>Files with HTTP headers</h3>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<p>The following directives will enable the <code>send-as-is</code>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholeshandler, which is used for files which contain their own HTTP headers.
0662ed52e814f8f08ef0e09956413a792584eddffuankgAll files in the <code>/web/htdocs/asis/</code> directory will be
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesprocessed by the <code>send-as-is</code> handler, regardless of their
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesfilename extensions.</p>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<pre>
0662ed52e814f8f08ef0e09956413a792584eddffuankg &lt;Directory /web/htdocs/asis&gt;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes SetHandler send-as-is
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes &lt;/Directory&gt;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</pre>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<hr>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<H2><a name="programmer">Programmer's Note</a></H2>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<P>In order to implement the handler features, an addition has been
0662ed52e814f8f08ef0e09956413a792584eddffuankgmade to the <A HREF="misc/API.html">Apache API</A> that you may wish to
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesmake use of. Specifically, a new record has been added to the
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<CODE>request_rec</CODE> structure:</P>
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg<PRE>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes char *handler
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</PRE>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<P>If you wish to have your module engage a handler, you need only to
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgset <CODE>r-&gt;handler</CODE> to the name of the handler at any time
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesprior to the <CODE>invoke_handler</CODE> stage of the
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesrequest. Handlers are implemented as they were before, albeit using
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesthe handler name instead of a content type. While it is not
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesnecessary, the naming convention for handlers is to use a
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesdash-separated word, with no slashes, so as to not invade the media
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholestype name-space.</P>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes<!--#include virtual="footer.html" -->
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</BODY>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes</HTML>
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes