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