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