]> granicus.if.org Git - apache/blob - docs/manual/handler.xml
Help doc writer to spot places where:
[apache] / docs / manual / handler.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="handler.xml.meta">
24
25   <title>Apache's Handler Use</title>
26
27   <summary>
28     <p>This document describes the use of Apache's Handlers.</p>
29   </summary>
30
31   <section id="definition">
32     <title>What is a Handler</title>
33     <related>
34       <modulelist>
35         <module>mod_actions</module>
36         <module>mod_asis</module>
37         <module>mod_cgi</module>
38         <module>mod_imagemap</module>
39         <module>mod_info</module>
40         <module>mod_mime</module>
41         <module>mod_negotiation</module>
42         <module>mod_status</module>
43      </modulelist>
44       <directivelist>
45         <directive module="mod_actions">Action</directive>
46         <directive module="mod_mime">AddHandler</directive>
47         <directive module="mod_mime">RemoveHandler</directive>
48         <directive module="core">SetHandler</directive>
49       </directivelist>
50     </related>
51
52
53     <p>A "handler" is an internal Apache representation of the
54     action to be performed when a file is called. Generally, files
55     have implicit handlers, based on the file type. Normally, all
56     files are simply served by the server, but certain file types
57     are "handled" separately.</p>
58
59     <p>Handlers may also be configured explicitly,
60     based on either filename extensions or on location,
61     without relation to file type. This is
62     advantageous both because it is a more elegant solution, and
63     because it also allows for both a type <strong>and</strong> a
64     handler to be associated with a file. (See also <a
65     href="mod/mod_mime.html#multipleext">Files with Multiple
66     Extensions</a>.)</p>
67
68     <p>Handlers can either be built into the server or included in
69     a module, or they can be added with the <directive
70     module="mod_actions">Action</directive> directive. The
71     built-in handlers in the standard distribution are as
72     follows:</p>
73
74     <ul>
75       <li><strong>default-handler</strong>: Send the file using the
76       <code>default_handler()</code>, which is the handler used by
77       default to handle static content. (core)</li>
78
79       <li><strong>send-as-is</strong>: Send file with HTTP headers
80       as is. (<module>mod_asis</module>)</li>
81
82       <li><strong>cgi-script</strong>: Treat the file as a CGI
83       script. (<module>mod_cgi</module>)</li>
84
85       <li><strong>imap-file</strong>: Parse as an imagemap rule
86       file. (<module>mod_imagemap</module>)</li>
87
88       <li><strong>server-info</strong>: Get the server's
89       configuration information. (<module>mod_info</module>)</li>
90
91       <li><strong>server-status</strong>: Get the server's status
92       report. (<module>mod_status</module>)</li>
93
94       <li><strong>type-map</strong>: Parse as a type map file for
95       content negotiation. (<module>mod_negotiation</module>)</li>
96     </ul>
97   </section>
98   <section id="examples">
99     <title>Examples</title>
100
101     <section id="example1">
102       <title>Modifying static content using a CGI script</title>
103
104       <p>The following directives will cause requests for files with
105       the <code>html</code> extension to trigger the launch of the
106       <code>footer.pl</code> CGI script.</p>
107
108       <highlight language="config">
109 Action add-footer /cgi-bin/footer.pl
110 AddHandler add-footer .html
111       </highlight>
112
113       <p>Then the CGI script is responsible for sending the
114       originally requested document (pointed to by the
115       <code>PATH_TRANSLATED</code> environment variable) and making
116       whatever modifications or additions are desired.</p>
117
118     </section>
119     <section id="example2">
120       <title>Files with HTTP headers</title>
121
122       <p>The following directives will enable the
123       <code>send-as-is</code> handler, which is used for files which
124       contain their own HTTP headers. All files in the
125       <code>/web/htdocs/asis/</code> directory will be processed by
126       the <code>send-as-is</code> handler, regardless of their
127       filename extensions.</p>
128
129       <highlight language="config">
130 &lt;Directory "/web/htdocs/asis"&gt;
131     SetHandler send-as-is
132 &lt;/Directory&gt;
133       </highlight>
134
135     </section>
136   </section>
137   <section id="programmer">
138     <title>Programmer's Note</title>
139
140     <p>In order to implement the handler features, an addition has
141     been made to the <a href="developer/API.html">Apache API</a> that
142     you may wish to make use of. Specifically, a new record has
143     been added to the <code>request_rec</code> structure:</p>
144
145     <highlight language="c">
146       char *handler
147     </highlight>
148
149     <p>If you wish to have your module engage a handler, you need
150     only to set <code>r-&gt;handler</code> to the name of the
151     handler at any time prior to the <code>invoke_handler</code>
152     stage of the request. Handlers are implemented as they were
153     before, albeit using the handler name instead of a content
154     type. While it is not necessary, the naming convention for
155     handlers is to use a dash-separated word, with no slashes, so
156     as to not invade the media type name-space.</p>
157   </section>
158 </manualpage>