switch to a 60 bit hash
[httpd-crcsyncproxy.git] / docs / manual / mod / mod_ext_filter.xml
blob250100212e08ae5b5b5507dff38ab2b6786db08a
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
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
14      http://www.apache.org/licenses/LICENSE-2.0
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 -->
23 <modulesynopsis metafile="mod_ext_filter.xml.meta">
25 <name>mod_ext_filter</name>
26 <description>Pass the response body through an external program before
27 delivery to the client</description>
28 <status>Extension</status>
29 <sourcefile>mod_ext_filter.c</sourcefile>
30 <identifier>ext_filter_module</identifier>
32 <summary>
33     <p><module>mod_ext_filter</module> presents a simple and familiar
34     programming model for <a href="../filter.html">filters</a>. With
35     this module, a program which reads from stdin and writes to stdout
36     (i.e., a Unix-style filter command) can be a filter for
37     Apache. This filtering mechanism is much slower than using a
38     filter which is specially written for the Apache API and runs
39     inside of the Apache server process, but it does have the
40     following benefits:</p>
42     <ul>
43       <li>the programming model is much simpler</li>
45       <li>any programming/scripting language can be used, provided
46       that it allows the program to read from standard input and
47       write to standard output</li>
49       <li>existing programs can be used unmodified as Apache
50       filters</li>
51     </ul>
53     <p>Even when the performance characteristics are not suitable
54     for production use, <module>mod_ext_filter</module> can be used as
55     a prototype environment for filters.</p>
57 </summary>
58 <seealso><a href="../filter.html">Filters</a></seealso>
60 <section id="examples"><title>Examples</title>
62     <section><title>Generating HTML from some other type of response</title>
63       <example>
64         # mod_ext_filter directive to define a filter<br />
65         # to HTML-ize text/c files using the external<br />
66         # program /usr/bin/enscript, with the type of<br />
67         # the result set to text/html<br />
68         ExtFilterDefine c-to-html mode=output \<br />
69         <indent>
70           intype=text/c outtype=text/html \<br />
71           cmd="/usr/bin/enscript --color -W html -Ec -o - -"<br />
72         </indent>
73         <br />
74         &lt;Directory "/export/home/trawick/apacheinst/htdocs/c"&gt;<br />
75         <indent>
76           # core directive to cause the new filter to<br />
77           # be run on output<br />
78           SetOutputFilter c-to-html<br />
79           <br />
80           # mod_mime directive to set the type of .c<br />
81           # files to text/c<br />
82           AddType text/c .c<br />
83           <br />
84           # mod_ext_filter directive to set the debug<br />
85           # level just high enough to see a log message<br />
86           # per request showing the configuration in force<br />
87           ExtFilterOptions DebugLevel=1<br />
88         </indent>
89         &lt;/Directory&gt;
90       </example>
91     </section>
93     <section><title>Implementing a content encoding filter</title>
94       <p>Note: this gzip example is just for the purposes of illustration.
95       Please refer to <module>mod_deflate</module> for a practical
96       implementation.</p>
98       <example>
99         # mod_ext_filter directive to define the external filter<br />
100         ExtFilterDefine gzip mode=output cmd=/bin/gzip<br />
101         <br />
102         &lt;Location /gzipped&gt;<br />
103         <indent>
104           # core directive to cause the gzip filter to be<br />
105           # run on output<br />
106           SetOutputFilter gzip<br />
107           <br />
108           # mod_header directive to add<br />
109           # "Content-Encoding: gzip" header field<br />
110           Header set Content-Encoding gzip<br />
111         </indent>
112         &lt;/Location&gt;
113       </example>
114     </section>
116     <section><title>Slowing down the server</title>
117       <example>
118         # mod_ext_filter directive to define a filter<br />
119         # which runs everything through cat; cat doesn't<br />
120         # modify anything; it just introduces extra pathlength<br />
121         # and consumes more resources<br />
122         ExtFilterDefine slowdown mode=output cmd=/bin/cat \<br />
123         <indent>
124           preservescontentlength<br />
125         </indent>
126         <br />
127         &lt;Location /&gt;<br />
128         <indent>
129           # core directive to cause the slowdown filter to<br />
130           # be run several times on output<br />
131           #<br />
132           SetOutputFilter slowdown;slowdown;slowdown<br />
133         </indent>
134         &lt;/Location&gt;
135       </example>
136     </section>
138     <section><title>Using sed to replace text in the response</title>
139       <example>
140         # mod_ext_filter directive to define a filter which<br />
141         # replaces text in the response<br />
142         #<br />
143         ExtFilterDefine fixtext mode=output intype=text/html \<br />
144         <indent>
145           cmd="/bin/sed s/verdana/arial/g"<br />
146         </indent>
147         <br />
148         &lt;Location /&gt;<br />
149         <indent>
150           # core directive to cause the fixtext filter to<br />
151           # be run on output<br />
152           SetOutputFilter fixtext<br />
153         </indent>
154         &lt;/Location&gt;
155       </example>
156     </section>
158     <section><title>Tracing another filter</title>
159       <example>
160         # Trace the data read and written by mod_deflate<br />
161         # for a particular client (IP 192.168.1.31)<br />
162         # experiencing compression problems.<br />
163         # This filter will trace what goes into mod_deflate.<br />
164         ExtFilterDefine tracebefore \<br />
165         <indent>
166           cmd="/bin/tracefilter.pl /tmp/tracebefore" \<br />
167           EnableEnv=trace_this_client<br />
168         </indent>
169         <br />
170         # This filter will trace what goes after mod_deflate.<br />
171         # Note that without the ftype parameter, the default<br />
172         # filter type of AP_FTYPE_RESOURCE would cause the<br />
173         # filter to be placed *before* mod_deflate in the filter<br />
174         # chain.  Giving it a numeric value slightly higher than<br />
175         # AP_FTYPE_CONTENT_SET will ensure that it is placed<br />
176         # after mod_deflate.<br />
177         ExtFilterDefine traceafter \<br />
178         <indent>
179           cmd="/bin/tracefilter.pl /tmp/traceafter" \<br />
180           EnableEnv=trace_this_client ftype=21<br />
181         </indent>
182         <br />
183         &lt;Directory /usr/local/docs&gt;<br />
184         <indent>
185           SetEnvIf Remote_Addr 192.168.1.31 trace_this_client<br />
186           SetOutputFilter tracebefore;deflate;traceafter<br />
187         </indent>
188         &lt;/Directory&gt;
189       </example>
191       <example><title>Here is the filter which traces the data:</title>
192         #!/usr/local/bin/perl -w<br />
193         use strict;<br />
194         <br />
195         open(SAVE, "&gt;$ARGV[0]")<br />
196         <indent>
197           or die "can't open $ARGV[0]: $?";<br />
198         </indent>
199         <br />
200         while (&lt;STDIN&gt;) {<br />
201         <indent>
202           print SAVE $_;<br />
203           print $_;<br />
204         </indent>
205         }<br />
206         <br />
207         close(SAVE);
208       </example>
209     </section>
210 </section> <!-- /Examples -->
212 <directivesynopsis>
213 <name>ExtFilterDefine</name>
214 <description>Define an external filter</description>
215 <syntax>ExtFilterDefine <var>filtername</var> <var>parameters</var></syntax>
216 <contextlist><context>server config</context></contextlist>
218 <usage>
219     <p>The <directive>ExtFilterDefine</directive> directive defines the
220     characteristics of an external filter, including the program to
221     run and its arguments.</p>
223     <p><var>filtername</var> specifies the name of the filter being
224     defined. This name can then be used in <directive module="core"
225     >SetOutputFilter</directive>
226     directives. It must be unique among all registered filters.
227     <em>At the present time, no error is reported by the
228     register-filter API, so a problem with duplicate names isn't
229     reported to the user.</em></p>
231     <p>Subsequent parameters can appear in any order and define the
232     external command to run and certain other characteristics. The
233     only required parameter is <code>cmd=</code>. These parameters
234     are:</p>
236     <dl>
237       <dt><code>cmd=<var>cmdline</var></code></dt>
239       <dd>The <code>cmd=</code> keyword allows you to specify the
240       external command to run. If there are arguments after the
241       program name, the command line should be surrounded in
242       quotation marks (<em>e.g.</em>, <code>cmd="<var>/bin/mypgm</var>
243       <var>arg1</var> <var>arg2</var>"</code>.) Normal shell quoting is
244       not necessary since the program is run directly, bypassing the shell.
245       Program arguments are blank-delimited. A backslash can be used to
246       escape blanks which should be part of a program argument. Any
247       backslashes which are part of the argument must be escaped with
248       backslash themselves.  In addition to the standard CGI environment
249       variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and 
250       QUERY_STRING_UNESCAPED will also be set for the program.</dd>
252       <dt><code>mode=<var>mode</var></code></dt>
254       <dd>Use <code>mode=output</code> (the default) for filters which
255       process the response.  Use <code>mode=input</code> for filters
256       which process the request.  <code>mode=input</code> is available
257       in Apache 2.1 and later.</dd>
259       <dt><code>intype=<var>imt</var></code></dt>
261       <dd>This parameter specifies the internet media type (<em>i.e.</em>,
262       MIME type) of documents which should be filtered. By default,
263       all documents are filtered. If <code>intype=</code> is
264       specified, the filter will be disabled for documents of other
265       types.</dd>
267       <dt><code>outtype=<var>imt</var></code></dt>
269       <dd>This parameter specifies the internet media type (<em>i.e.</em>,
270       MIME type) of filtered documents. It is useful when the
271       filter changes the internet media type as part of the
272       filtering operation. By default, the internet media type is
273       unchanged.</dd>
275       <dt><code>PreservesContentLength</code></dt>
277       <dd>The <code>PreservesContentLength</code> keyword specifies
278       that the filter preserves the content length. This is not the
279       default, as most filters change the content length. In the
280       event that the filter doesn't modify the length, this keyword
281       should be specified.</dd>
283       <dt><code>ftype=<var>filtertype</var></code></dt>
285       <dd>This parameter specifies the numeric value for filter type
286       that the filter should be registered as.  The default value,
287       AP_FTYPE_RESOURCE, is sufficient in most cases.  If the filter
288       needs to operate at a different point in the filter chain than
289       resource filters, then this parameter will be necessary.  See
290       the AP_FTYPE_foo definitions in util_filter.h for appropriate
291       values.</dd>
293       <dt><code>disableenv=<var>env</var></code></dt>
295       <dd>This parameter specifies the name of an environment variable
296       which, if set, will disable the filter.</dd>
298       <dt><code>enableenv=<var>env</var></code></dt>
300       <dd>This parameter specifies the name of an environment variable
301       which must be set, or the filter will be disabled.</dd>
302     </dl>
303 </usage>
304 </directivesynopsis>
306 <directivesynopsis>
307 <name>ExtFilterOptions</name>
308 <description>Configure <module>mod_ext_filter</module> options</description>
309 <syntax>ExtFilterOptions <var>option</var> [<var>option</var>] ...</syntax>
310 <default>ExtFilterOptions DebugLevel=0 NoLogStderr</default>
311 <contextlist><context>directory</context></contextlist>
313 <usage>
314     <p>The <directive>ExtFilterOptions</directive> directive specifies
315     special processing options for <module>mod_ext_filter</module>.
316     <var>Option</var> can be one of</p>
318     <dl>
319       <dt><code>DebugLevel=<var>n</var></code></dt>
321       <dd>
322         The <code>DebugLevel</code> keyword allows you to specify
323         the level of debug messages generated by
324         <module>mod_ext_filter</module>. By default, no debug messages
325         are generated. This is equivalent to
326         <code>DebugLevel=0</code>. With higher numbers, more debug
327         messages are generated, and server performance will be
328         degraded. The actual meanings of the numeric values are
329         described with the definitions of the DBGLVL_ constants
330         near the beginning of <code>mod_ext_filter.c</code>. 
332         <p>Note: The core directive <directive module="core"
333         >LogLevel</directive> should be used to cause debug messages to
334         be stored in the Apache error log.</p>
335       </dd>
337       <dt><code>LogStderr | NoLogStderr</code></dt>
339       <dd>The <code>LogStderr</code> keyword specifies that
340       messages written to standard error by the external filter
341       program will be saved in the Apache error log.
342       <code>NoLogStderr</code> disables this feature.</dd>
344       <dt><code>Onfail=[abort|remove]</code></dt>
345       <dd>Determines how to proceed if the external filter program
346       cannot be started.  With <code>abort</code> (the default value)
347       the request will be aborted.  With <code>remove</code>, the
348       filter is removed and the request continues without it.</dd>
349     </dl>
351     <example><title>Example</title>
352       ExtFilterOptions LogStderr DebugLevel=0
353     </example>
355     <p>Messages written to the filter's standard error will be stored
356     in the Apache error log. No debug messages will be generated by
357     <module>mod_ext_filter</module>. </p>
358 </usage>
359 </directivesynopsis>
361 </modulesynopsis>