1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 5 6<html xmlns="http://www.w3.org/1999/xhtml"> 7 <head> 8 <meta name="generator" content="HTML Tidy, see www.w3.org" /> 9 10 <title>Apache's Handler Use</title> 11 </head> 12 <!-- Background white, links blue (unvisited), navy (visited), red (active) --> 13 14 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" 15 vlink="#000080" alink="#FF0000"> 16 <div align="CENTER"> 17 <img src="images/sub.gif" alt="[APACHE DOCUMENTATION]" /> 18 19 <h3>Apache HTTP Server</h3> 20 </div> 21 22 23 24 <h1 align="CENTER">Apache's Handler Use</h1> 25 26 <ul> 27 <li><a href="#definition">What is a Handler</a></li> 28 29 <li><a href="#examples">Examples</a></li> 30 31 <li><a href="#programmer">Programmer's Note</a></li> 32 </ul> 33 <hr /> 34 35 <h2><a id="definition" name="definition">What is a 36 Handler</a></h2> 37 38 <table border="1"> 39 <tr> 40 <td valign="top"><strong>Related Modules</strong><br /> 41 <br /> 42 <a href="mod/mod_actions.html">mod_actions</a><br /> 43 <a href="mod/mod_asis.html">mod_asis</a><br /> 44 <a href="mod/mod_cgi.html">mod_cgi</a><br /> 45 <a href="mod/mod_imap.html">mod_imap</a><br /> 46 <a href="mod/mod_info.html">mod_info</a><br /> 47 <a href="mod/mod_include.html">mod_include</a><br /> 48 <a href="mod/mod_mime.html">mod_mime</a><br /> 49 <a 50 href="mod/mod_negotiation.html">mod_negotiation</a><br /> 51 <a href="mod/mod_status.html">mod_status</a><br /> 52 </td> 53 54 <td valign="top"><strong>Related Directives</strong><br /> 55 <br /> 56 <a href="mod/mod_actions.html#action">Action</a><br /> 57 <a 58 href="mod/mod_mime.html#addhandler">AddHandler</a><br /> 59 <a 60 href="mod/mod_mime.html#removehandler">RemoveHandler</a><br /> 61 <a 62 href="mod/mod_mime.html#sethandler">SetHandler</a><br /> 63 </td> 64 </tr> 65 </table> 66 67 <p>A "handler" is an internal Apache representation of the 68 action to be performed when a file is called. Generally, files 69 have implicit handlers, based on the file type. Normally, all 70 files are simply served by the server, but certain file types 71 are "handled" separately.</p> 72 73 <p>Apache 1.1 adds the ability to use handlers explicitly. 74 Based on either filename extensions or on location, handlers 75 can be specified without relation to file type. This is 76 advantageous both because it is a more elegant solution, and 77 because it also allows for both a type <strong>and</strong> a 78 handler to be associated with a file. (See also <a 79 href="mod/mod_mime.html#multipleext">Files with Multiple 80 Extensions</a>.)</p> 81 82 <p>Handlers can either be built into the server or included in 83 a module, or they can be added with the <a 84 href="mod/mod_actions.html#action">Action</a> directive. The 85 built-in handlers in the standard distribution are as 86 follows:</p> 87 88 <ul> 89 <li><strong>default-handler</strong>: Send the file using the 90 <code>default_handler()</code>, which is the handler used by 91 default to handle static content. (core)</li> 92 93 <li><strong>send-as-is</strong>: Send file with HTTP headers 94 as is. (<a href="mod/mod_asis.html">mod_asis</a>)</li> 95 96 <li><strong>cgi-script</strong>: Treat the file as a CGI 97 script. (<a href="mod/mod_cgi.html">mod_cgi</a>)</li> 98 99 <li><strong>imap-file</strong>: Parse as an imagemap rule 100 file. (<a href="mod/mod_imap.html">mod_imap</a>)</li> 101 102 <li><strong>server-info</strong>: Get the server's 103 configuration information. (<a 104 href="mod/mod_info.html">mod_info</a>)</li> 105 106 <li><strong>server-parsed</strong>: Parse for server-side 107 includes. (<a 108 href="mod/mod_include.html">mod_include</a>)</li> 109 110 <li><strong>server-status</strong>: Get the server's status 111 report. (<a href="mod/mod_status.html">mod_status</a>)</li> 112 113 <li><strong>type-map</strong>: Parse as a type map file for 114 content negotiation. (<a 115 href="mod/mod_negotiation.html">mod_negotiation</a>)</li> 116 </ul> 117 <hr /> 118 119 <h2><a id="examples" name="examples">Examples</a></h2> 120 121 <h3>Modifying static content using a CGI script</h3> 122 123 <p>The following directives will cause requests for files with 124 the <code>html</code> extension to trigger the launch of the 125 <code>footer.pl</code> CGI script.</p> 126<pre> 127 Action add-footer /cgi-bin/footer.pl 128 AddHandler add-footer .html 129</pre> 130 131 <p>Then the CGI script is responsible for sending the 132 originally requested document (pointed to by the 133 <code>PATH_TRANSLATED</code> environment variable) and making 134 whatever modifications or additions are desired.</p> 135 136 <h3>Files with HTTP headers</h3> 137 138 <p>The following directives will enable the 139 <code>send-as-is</code> handler, which is used for files which 140 contain their own HTTP headers. All files in the 141 <code>/web/htdocs/asis/</code> directory will be processed by 142 the <code>send-as-is</code> handler, regardless of their 143 filename extensions.</p> 144<pre> 145 <Directory /web/htdocs/asis> 146 SetHandler send-as-is 147 </Directory> 148</pre> 149 <hr /> 150 151 <h2><a id="programmer" name="programmer">Programmer's 152 Note</a></h2> 153 154 <p>In order to implement the handler features, an addition has 155 been made to the <a href="misc/API.html">Apache API</a> that 156 you may wish to make use of. Specifically, a new record has 157 been added to the <code>request_rec</code> structure:</p> 158<pre> 159 char *handler 160</pre> 161 162 <p>If you wish to have your module engage a handler, you need 163 only to set <code>r->handler</code> to the name of the 164 handler at any time prior to the <code>invoke_handler</code> 165 stage of the request. Handlers are implemented as they were 166 before, albeit using the handler name instead of a content 167 type. While it is not necessary, the naming convention for 168 handlers is to use a dash-separated word, with no slashes, so 169 as to not invade the media type name-space.</p> 170 <hr /> 171 172 <h3 align="CENTER">Apache HTTP Server</h3> 173 <a href="./"><img src="images/index.gif" alt="Index" /></a> 174 175 </body> 176</html> 177 178 179 180