1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>mod_ext_filter - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
14 <div id="page-header">
15 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
16 <p class="apache">Apache HTTP Server Version 2.0</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
20 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.0</a> > <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_ext_filter</h1>
24 <p><span>Available Languages: </span><a href="../en/mod/mod_ext_filter.html" title="English"> en </a> |
25 <a href="../ko/mod/mod_ext_filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
27 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Pass the response body through an external program before
28 delivery to the client</td></tr>
29 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
30 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>ext_filter_module</td></tr>
31 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_ext_filter.c</td></tr></table>
34 <p><code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> presents a simple and familiar
35 programming model for <a href="../filter.html">filters</a>. With
36 this module, a program which reads from stdin and writes to stdout
37 (i.e., a Unix-style filter command) can be a filter for
38 Apache. This filtering mechanism is much slower than using a
39 filter which is specially written for the Apache API and runs
40 inside of the Apache server process, but it does have the
41 following benefits:</p>
44 <li>the programming model is much simpler</li>
46 <li>any programming/scripting language can be used, provided
47 that it allows the program to read from standard input and
48 write to standard output</li>
50 <li>existing programs can be used unmodified as Apache
54 <p>Even when the performance characteristics are not suitable
55 for production use, <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> can be used as
56 a prototype environment for filters.</p>
59 <div id="quickview"><h3 class="directives">Directives</h3>
61 <li><img alt="" src="../images/down.gif" /> <a href="#extfilterdefine">ExtFilterDefine</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#extfilteroptions">ExtFilterOptions</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#examples">Examples</a></li>
67 </ul><h3>See also</h3>
69 <li><a href="../filter.html">Filters</a></li>
71 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
73 <h2><a name="examples" id="examples">Examples</a></h2>
75 <h3>Generating HTML from some other type of response</h3>
76 <div class="example"><p><code>
77 # mod_ext_filter directive to define a filter<br />
78 # to HTML-ize text/c files using the external<br />
79 # program /usr/bin/enscript, with the type of<br />
80 # the result set to text/html<br />
81 ExtFilterDefine c-to-html mode=output \<br />
83 intype=text/c outtype=text/html \<br />
84 cmd="/usr/bin/enscript --color -W html -Ec -o - -"<br />
87 <Directory "/export/home/trawick/apacheinst/htdocs/c"><br />
89 # core directive to cause the new filter to<br />
90 # be run on output<br />
91 SetOutputFilter c-to-html<br />
93 # mod_mime directive to set the type of .c<br />
94 # files to text/c<br />
95 AddType text/c .c<br />
97 # mod_ext_filter directive to set the debug<br />
98 # level just high enough to see a log message<br />
99 # per request showing the configuration in force<br />
100 ExtFilterOptions DebugLevel=1<br />
106 <h3>Implementing a content encoding filter</h3>
107 <p>Note: this gzip example is just for the purposes of illustration.
108 Please refer to <code class="module"><a href="../mod/mod_deflate.html">mod_deflate</a></code> for a practical
111 <div class="example"><p><code>
112 # mod_ext_filter directive to define the external filter<br />
113 ExtFilterDefine gzip mode=output cmd=/bin/gzip<br />
115 <Location /gzipped><br />
116 <span class="indent">
117 # core directive to cause the gzip filter to be<br />
118 # run on output<br />
119 SetOutputFilter gzip<br />
121 # mod_header directive to add<br />
122 # "Content-Encoding: gzip" header field<br />
123 Header set Content-Encoding gzip<br />
129 <h3>Slowing down the server</h3>
130 <div class="example"><p><code>
131 # mod_ext_filter directive to define a filter<br />
132 # which runs everything through cat; cat doesn't<br />
133 # modify anything; it just introduces extra pathlength<br />
134 # and consumes more resources<br />
135 ExtFilterDefine slowdown mode=output cmd=/bin/cat \<br />
136 <span class="indent">
137 preservescontentlength<br />
140 <Location /><br />
141 <span class="indent">
142 # core directive to cause the slowdown filter to<br />
143 # be run several times on output<br />
145 SetOutputFilter slowdown;slowdown;slowdown<br />
151 <h3>Using sed to replace text in the response</h3>
152 <div class="example"><p><code>
153 # mod_ext_filter directive to define a filter which<br />
154 # replaces text in the response<br />
156 ExtFilterDefine fixtext mode=output intype=text/html \<br />
157 <span class="indent">
158 cmd="/bin/sed s/verdana/arial/g"<br />
161 <Location /><br />
162 <span class="indent">
163 # core directive to cause the fixtext filter to<br />
164 # be run on output<br />
165 SetOutputFilter fixtext<br />
171 <h3>Tracing another filter</h3>
172 <div class="example"><p><code>
173 # Trace the data read and written by mod_deflate<br />
174 # for a particular client (IP 192.168.1.31)<br />
175 # experiencing compression problems.<br />
176 # This filter will trace what goes into mod_deflate.<br />
177 ExtFilterDefine tracebefore \<br />
178 <span class="indent">
179 cmd="/bin/tracefilter.pl /tmp/tracebefore" \<br />
180 EnableEnv=trace_this_client<br />
183 # This filter will trace what goes after mod_deflate.<br />
184 # Note that without the ftype parameter, the default<br />
185 # filter type of AP_FTYPE_RESOURCE would cause the<br />
186 # filter to be placed *before* mod_deflate in the filter<br />
187 # chain. Giving it a numeric value slightly higher than<br />
188 # AP_FTYPE_CONTENT_SET will ensure that it is placed<br />
189 # after mod_deflate.<br />
190 ExtFilterDefine traceafter \<br />
191 <span class="indent">
192 cmd="/bin/tracefilter.pl /tmp/traceafter" \<br />
193 EnableEnv=trace_this_client ftype=21<br />
196 <Directory /usr/local/docs><br />
197 <span class="indent">
198 SetEnvIf Remote_Addr 192.168.1.31 trace_this_client<br />
199 SetOutputFilter tracebefore;deflate;traceafter<br />
204 <div class="example"><h3>Here is the filter which traces the data:</h3><p><code>
205 #!/usr/local/bin/perl -w<br />
208 open(SAVE, ">$ARGV[0]")<br />
209 <span class="indent">
210 or die "can't open $ARGV[0]: $?";<br />
213 while (<STDIN>) {<br />
214 <span class="indent">
224 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
225 <div class="directive-section"><h2><a name="ExtFilterDefine" id="ExtFilterDefine">ExtFilterDefine</a> <a name="extfilterdefine" id="extfilterdefine">Directive</a></h2>
226 <table class="directive">
227 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Define an external filter</td></tr>
228 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ExtFilterDefine <var>filtername</var> <var>parameters</var></code></td></tr>
229 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
230 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
231 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_ext_filter</td></tr>
233 <p>The <code class="directive">ExtFilterDefine</code> directive defines the
234 characteristics of an external filter, including the program to
235 run and its arguments.</p>
237 <p><var>filtername</var> specifies the name of the filter being
238 defined. This name can then be used in SetOutputFilter
239 directives. It must be unique among all registered filters.
240 <em>At the present time, no error is reported by the
241 register-filter API, so a problem with duplicate names isn't
242 reported to the user.</em></p>
244 <p>Subsequent parameters can appear in any order and define the
245 external command to run and certain other characteristics. The
246 only required parameter is <code>cmd=</code>. These parameters
250 <dt><code>cmd=<var>cmdline</var></code></dt>
252 <dd>The <code>cmd=</code> keyword allows you to specify the
253 external command to run. If there are arguments after the
254 program name, the command line should be surrounded in
255 quotation marks (<em>e.g.</em>, <code>cmd="<var>/bin/mypgm</var>
256 <var>arg1</var> <var>arg2</var>"</code>. Normal shell quoting is
257 not necessary since the program is run directly, bypassing the shell.
258 Program arguments are blank-delimited. A backslash can be used to
259 escape blanks which should be part of a program argument. Any
260 backslashes which are part of the argument must be escaped with
261 backslash themselves. In addition to the standard CGI environment
262 variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and
263 QUERY_STRING_UNESCAPED will also be set for the program.</dd>
265 <dt><code>mode=<var>mode</var></code></dt>
267 <dd><code>mode</code> should be <code>output</code> for now (the
268 default). In the future, <code>mode=input</code> will be used to
269 specify a filter for request bodies.</dd>
271 <dt><code>intype=<var>imt</var></code></dt>
273 <dd>This parameter specifies the internet media type (<em>i.e.</em>,
274 MIME type) of documents which should be filtered. By default,
275 all documents are filtered. If <code>intype=</code> is
276 specified, the filter will be disabled for documents of other
279 <dt><code>outtype=<var>imt</var></code></dt>
281 <dd>This parameter specifies the internet media type (<em>i.e.</em>,
282 MIME type) of filtered documents. It is useful when the
283 filter changes the internet media type as part of the
284 filtering operation. By default, the internet media type is
287 <dt><code>PreservesContentLength</code></dt>
289 <dd>The <code>PreservesContentLength</code> keyword specifies
290 that the filter preserves the content length. This is not the
291 default, as most filters change the content length. In the
292 event that the filter doesn't modify the length, this keyword
293 should be specified.</dd>
295 <dt><code>ftype=<var>filtertype</var></code></dt>
297 <dd>This parameter specifies the numeric value for filter type
298 that the filter should be registered as. The default value,
299 AP_FTYPE_RESOURCE, is sufficient in most cases. If the filter
300 needs to operate at a different point in the filter chain than
301 resource filters, then this parameter will be necessary. See
302 the AP_FTYPE_foo definitions in util_filter.h for appropriate
305 <dt><code>disableenv=<var>env</var></code></dt>
307 <dd>This parameter specifies the name of an environment variable
308 which, if set, will disable the filter.</dd>
310 <dt><code>enableenv=<var>env</var></code></dt>
312 <dd>This parameter specifies the name of an environment variable
313 which must be set, or the filter will be disabled.</dd>
317 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
318 <div class="directive-section"><h2><a name="ExtFilterOptions" id="ExtFilterOptions">ExtFilterOptions</a> <a name="extfilteroptions" id="extfilteroptions">Directive</a></h2>
319 <table class="directive">
320 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> options</td></tr>
321 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ExtFilterOptions <var>option</var> [<var>option</var>] ...</code></td></tr>
322 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>ExtFilterOptions DebugLevel=0 NoLogStderr</code></td></tr>
323 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory</td></tr>
324 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
325 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_ext_filter</td></tr>
327 <p>The <code class="directive">ExtFilterOptions</code> directive specifies
328 special processing options for <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>.
329 <var>Option</var> can be one of</p>
332 <dt><code>DebugLevel=<var>n</var></code></dt>
335 The <code>DebugLevel</code> keyword allows you to specify
336 the level of debug messages generated by
337 <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>. By default, no debug messages
338 are generated. This is equivalent to
339 <code>DebugLevel=0</code>. With higher numbers, more debug
340 messages are generated, and server performance will be
341 degraded. The actual meanings of the numeric values are
342 described with the definitions of the DBGLVL_ constants
343 near the beginning of <code>mod_ext_filter.c</code>.
345 <p>Note: The core directive <code class="directive"><a href="../mod/core.html#loglevel">LogLevel</a></code> should be used to cause debug messages to
346 be stored in the Apache error log.</p>
349 <dt><code>LogStderr | NoLogStderr</code></dt>
351 <dd>The <code>LogStderr</code> keyword specifies that
352 messages written to standard error by the external filter
353 program will be saved in the Apache error log.
354 <code>NoLogStderr</code> disables this feature.</dd>
357 <div class="example"><h3>Example</h3><p><code>
358 ExtFilterOptions LogStderr DebugLevel=0
361 <p>Messages written to the filter's standard error will be stored
362 in the Apache error log. No debug messages will be generated by
363 <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>. </p>
367 <div class="bottomlang">
368 <p><span>Available Languages: </span><a href="../en/mod/mod_ext_filter.html" title="English"> en </a> |
369 <a href="../ko/mod/mod_ext_filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
370 </div><div id="footer">
371 <p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
372 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>