2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
6 Copyright 2002-2004 The Apache Software Foundation
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
12 http://www.apache.org/licenses/LICENSE-2.0
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.
21 <modulesynopsis metafile="mod_ext_filter.xml.meta">
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>
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>
41 <li>the programming model is much simpler</li>
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>
47 <li>existing programs can be used unmodified as Apache
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>
56 <seealso><a href="../filter.html">Filters</a></seealso>
58 <section id="examples"><title>Examples</title>
60 <section><title>Generating HTML from some other type of response</title>
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 />
68 intype=text/c outtype=text/html \<br />
69 cmd="/usr/bin/enscript --color -W html -Ec -o - -"<br />
72 <Directory "/export/home/trawick/apacheinst/htdocs/c"><br />
74 # core directive to cause the new filter to<br />
75 # be run on output<br />
76 SetOutputFilter c-to-html<br />
78 # mod_mime directive to set the type of .c<br />
79 # files to text/c<br />
80 AddType text/c .c<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 />
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
97 # mod_ext_filter directive to define the external filter<br />
98 ExtFilterDefine gzip mode=output cmd=/bin/gzip<br />
100 <Location /gzipped><br />
102 # core directive to cause the gzip filter to be<br />
103 # run on output<br />
104 SetOutputFilter gzip<br />
106 # mod_header directive to add<br />
107 # "Content-Encoding: gzip" header field<br />
108 Header set Content-Encoding gzip<br />
114 <section><title>Slowing down the server</title>
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 />
122 preservescontentlength<br />
125 <Location /><br />
127 # core directive to cause the slowdown filter to<br />
128 # be run several times on output<br />
130 SetOutputFilter slowdown;slowdown;slowdown<br />
136 <section><title>Using sed to replace text in the response</title>
138 # mod_ext_filter directive to define a filter which<br />
139 # replaces text in the response<br />
141 ExtFilterDefine fixtext mode=output intype=text/html \<br />
143 cmd="/bin/sed s/verdana/arial/g"<br />
146 <Location /><br />
148 # core directive to cause the fixtext filter to<br />
149 # be run on output<br />
150 SetOutputFilter fixtext<br />
156 <section><title>Tracing another filter</title>
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 />
164 cmd="/bin/tracefilter.pl /tmp/tracebefore" \<br />
165 EnableEnv=trace_this_client<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 />
177 cmd="/bin/tracefilter.pl /tmp/traceafter" \<br />
178 EnableEnv=trace_this_client ftype=21<br />
181 <Directory /usr/local/docs><br />
183 SetEnvIf Remote_Addr 192.168.1.31 trace_this_client<br />
184 SetOutputFilter tracebefore;deflate;traceafter<br />
189 <example><title>Here is the filter which traces the data:</title>
190 #!/usr/local/bin/perl -w<br />
193 open(SAVE, ">$ARGV[0]")<br />
195 or die "can't open $ARGV[0]: $?";<br />
198 while (<STDIN>) {<br />
208 </section> <!-- /Examples -->
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>
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>
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>
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
234 <dt><code>cmd=<var>cmdline</var></code></dt>
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>
249 <dt><code>mode=<var>mode</var></code></dt>
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
256 <dt><code>intype=<var>imt</var></code></dt>
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
264 <dt><code>outtype=<var>imt</var></code></dt>
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
272 <dt><code>PreservesContentLength</code></dt>
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>
280 <dt><code>ftype=<var>filtertype</var></code></dt>
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
290 <dt><code>disableenv=<var>env</var></code></dt>
292 <dd>This parameter specifies the name of an environment variable
293 which, if set, will disable the filter.</dd>
295 <dt><code>enableenv=<var>env</var></code></dt>
297 <dd>This parameter specifies the name of an environment variable
298 which must be set, or the filter will be disabled.</dd>
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>
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>
316 <dt><code>DebugLevel=<var>n</var></code></dt>
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>.
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>
334 <dt><code>LogStderr | NoLogStderr</code></dt>
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>
342 <example><title>Example</title>
343 ExtFilterOptions LogStderr DebugLevel=0
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>