]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_ext_filter.xml
mod_reqtimeout: Change the default to set some reasonable timeout values if loaded
[apache] / docs / manual / mod / mod_ext_filter.xml
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$ -->
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 <modulesynopsis metafile="mod_ext_filter.xml.meta">
24
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>
31
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>
41
42     <ul>
43       <li>the programming model is much simpler</li>
44
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>
48
49       <li>existing programs can be used unmodified as Apache
50       filters</li>
51     </ul>
52
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>
56
57 </summary>
58 <seealso><a href="../filter.html">Filters</a></seealso>
59
60 <section id="examples"><title>Examples</title>
61
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         </indent>
85         &lt;/Directory&gt;
86       </example>
87     </section>
88
89     <section><title>Implementing a content encoding filter</title>
90       <p>Note: this gzip example is just for the purposes of illustration.
91       Please refer to <module>mod_deflate</module> for a practical
92       implementation.</p>
93
94       <example>
95         # mod_ext_filter directive to define the external filter<br />
96         ExtFilterDefine gzip mode=output cmd=/bin/gzip<br />
97         <br />
98         &lt;Location /gzipped&gt;<br />
99         <indent>
100           # core directive to cause the gzip filter to be<br />
101           # run on output<br />
102           SetOutputFilter gzip<br />
103           <br />
104           # mod_header directive to add<br />
105           # "Content-Encoding: gzip" header field<br />
106           Header set Content-Encoding gzip<br />
107         </indent>
108         &lt;/Location&gt;
109       </example>
110     </section>
111
112     <section><title>Slowing down the server</title>
113       <example>
114         # mod_ext_filter directive to define a filter<br />
115         # which runs everything through cat; cat doesn't<br />
116         # modify anything; it just introduces extra pathlength<br />
117         # and consumes more resources<br />
118         ExtFilterDefine slowdown mode=output cmd=/bin/cat \<br />
119         <indent>
120           preservescontentlength<br />
121         </indent>
122         <br />
123         &lt;Location /&gt;<br />
124         <indent>
125           # core directive to cause the slowdown filter to<br />
126           # be run several times on output<br />
127           #<br />
128           SetOutputFilter slowdown;slowdown;slowdown<br />
129         </indent>
130         &lt;/Location&gt;
131       </example>
132     </section>
133
134     <section><title>Using sed to replace text in the response</title>
135       <example>
136         # mod_ext_filter directive to define a filter which<br />
137         # replaces text in the response<br />
138         #<br />
139         ExtFilterDefine fixtext mode=output intype=text/html \<br />
140         <indent>
141           cmd="/bin/sed s/verdana/arial/g"<br />
142         </indent>
143         <br />
144         &lt;Location /&gt;<br />
145         <indent>
146           # core directive to cause the fixtext filter to<br />
147           # be run on output<br />
148           SetOutputFilter fixtext<br />
149         </indent>
150         &lt;/Location&gt;
151       </example>
152     </section>
153
154     <section><title>Tracing another filter</title>
155       <example>
156         # Trace the data read and written by mod_deflate<br />
157         # for a particular client (IP 192.168.1.31)<br />
158         # experiencing compression problems.<br />
159         # This filter will trace what goes into mod_deflate.<br />
160         ExtFilterDefine tracebefore \<br />
161         <indent>
162           cmd="/bin/tracefilter.pl /tmp/tracebefore" \<br />
163           EnableEnv=trace_this_client<br />
164         </indent>
165         <br />
166         # This filter will trace what goes after mod_deflate.<br />
167         # Note that without the ftype parameter, the default<br />
168         # filter type of AP_FTYPE_RESOURCE would cause the<br />
169         # filter to be placed *before* mod_deflate in the filter<br />
170         # chain.  Giving it a numeric value slightly higher than<br />
171         # AP_FTYPE_CONTENT_SET will ensure that it is placed<br />
172         # after mod_deflate.<br />
173         ExtFilterDefine traceafter \<br />
174         <indent>
175           cmd="/bin/tracefilter.pl /tmp/traceafter" \<br />
176           EnableEnv=trace_this_client ftype=21<br />
177         </indent>
178         <br />
179         &lt;Directory /usr/local/docs&gt;<br />
180         <indent>
181           SetEnvIf Remote_Addr 192.168.1.31 trace_this_client<br />
182           SetOutputFilter tracebefore;deflate;traceafter<br />
183         </indent>
184         &lt;/Directory&gt;
185       </example>
186
187       <example><title>Here is the filter which traces the data:</title>
188         #!/usr/local/bin/perl -w<br />
189         use strict;<br />
190         <br />
191         open(SAVE, "&gt;$ARGV[0]")<br />
192         <indent>
193           or die "can't open $ARGV[0]: $?";<br />
194         </indent>
195         <br />
196         while (&lt;STDIN&gt;) {<br />
197         <indent>
198           print SAVE $_;<br />
199           print $_;<br />
200         </indent>
201         }<br />
202         <br />
203         close(SAVE);
204       </example>
205     </section>
206 </section> <!-- /Examples -->
207
208 <directivesynopsis>
209 <name>ExtFilterDefine</name>
210 <description>Define an external filter</description>
211 <syntax>ExtFilterDefine <var>filtername</var> <var>parameters</var></syntax>
212 <contextlist><context>server config</context></contextlist>
213
214 <usage>
215     <p>The <directive>ExtFilterDefine</directive> directive defines the
216     characteristics of an external filter, including the program to
217     run and its arguments.</p>
218
219     <p><var>filtername</var> specifies the name of the filter being
220     defined. This name can then be used in <directive module="core"
221     >SetOutputFilter</directive>
222     directives. It must be unique among all registered filters.
223     <em>At the present time, no error is reported by the
224     register-filter API, so a problem with duplicate names isn't
225     reported to the user.</em></p>
226
227     <p>Subsequent parameters can appear in any order and define the
228     external command to run and certain other characteristics. The
229     only required parameter is <code>cmd=</code>. These parameters
230     are:</p>
231
232     <dl>
233       <dt><code>cmd=<var>cmdline</var></code></dt>
234
235       <dd>The <code>cmd=</code> keyword allows you to specify the
236       external command to run. If there are arguments after the
237       program name, the command line should be surrounded in
238       quotation marks (<em>e.g.</em>, <code>cmd="<var>/bin/mypgm</var>
239       <var>arg1</var> <var>arg2</var>"</code>.) Normal shell quoting is
240       not necessary since the program is run directly, bypassing the shell.
241       Program arguments are blank-delimited. A backslash can be used to
242       escape blanks which should be part of a program argument. Any
243       backslashes which are part of the argument must be escaped with
244       backslash themselves.  In addition to the standard CGI environment
245       variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and
246       QUERY_STRING_UNESCAPED will also be set for the program.</dd>
247
248       <dt><code>mode=<var>mode</var></code></dt>
249
250       <dd>Use <code>mode=output</code> (the default) for filters which
251       process the response.  Use <code>mode=input</code> for filters
252       which process the request.  <code>mode=input</code> is available
253       in Apache 2.1 and later.</dd>
254
255       <dt><code>intype=<var>imt</var></code></dt>
256
257       <dd>This parameter specifies the internet media type (<em>i.e.</em>,
258       MIME type) of documents which should be filtered. By default,
259       all documents are filtered. If <code>intype=</code> is
260       specified, the filter will be disabled for documents of other
261       types.</dd>
262
263       <dt><code>outtype=<var>imt</var></code></dt>
264
265       <dd>This parameter specifies the internet media type (<em>i.e.</em>,
266       MIME type) of filtered documents. It is useful when the
267       filter changes the internet media type as part of the
268       filtering operation. By default, the internet media type is
269       unchanged.</dd>
270
271       <dt><code>PreservesContentLength</code></dt>
272
273       <dd>The <code>PreservesContentLength</code> keyword specifies
274       that the filter preserves the content length. This is not the
275       default, as most filters change the content length. In the
276       event that the filter doesn't modify the length, this keyword
277       should be specified.</dd>
278
279       <dt><code>ftype=<var>filtertype</var></code></dt>
280
281       <dd>This parameter specifies the numeric value for filter type
282       that the filter should be registered as.  The default value,
283       AP_FTYPE_RESOURCE, is sufficient in most cases.  If the filter
284       needs to operate at a different point in the filter chain than
285       resource filters, then this parameter will be necessary.  See
286       the AP_FTYPE_foo definitions in util_filter.h for appropriate
287       values.</dd>
288
289       <dt><code>disableenv=<var>env</var></code></dt>
290
291       <dd>This parameter specifies the name of an environment variable
292       which, if set, will disable the filter.</dd>
293
294       <dt><code>enableenv=<var>env</var></code></dt>
295
296       <dd>This parameter specifies the name of an environment variable
297       which must be set, or the filter will be disabled.</dd>
298     </dl>
299 </usage>
300 </directivesynopsis>
301
302 <directivesynopsis>
303 <name>ExtFilterOptions</name>
304 <description>Configure <module>mod_ext_filter</module> options</description>
305 <syntax>ExtFilterOptions <var>option</var> [<var>option</var>] ...</syntax>
306 <default>ExtFilterOptions NoLogStderr</default>
307 <contextlist><context>directory</context></contextlist>
308
309 <usage>
310     <p>The <directive>ExtFilterOptions</directive> directive specifies
311     special processing options for <module>mod_ext_filter</module>.
312     <var>Option</var> can be one of</p>
313
314     <dl>
315       <dt><code>LogStderr | NoLogStderr</code></dt>
316
317       <dd>The <code>LogStderr</code> keyword specifies that
318       messages written to standard error by the external filter
319       program will be saved in the Apache error log.
320       <code>NoLogStderr</code> disables this feature.</dd>
321
322       <dt><code>Onfail=[abort|remove]</code></dt>
323       <dd>Determines how to proceed if the external filter program
324       cannot be started.  With <code>abort</code> (the default value)
325       the request will be aborted.  With <code>remove</code>, the
326       filter is removed and the request continues without it.</dd>
327     </dl>
328
329     <example><title>Example</title>
330       ExtFilterOptions LogStderr
331     </example>
332
333     <p>Messages written to the filter's standard error will be stored
334     in the Apache error log.</p>
335 </usage>
336 </directivesynopsis>
337
338 </modulesynopsis>