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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 This file is generated from xml source: DO NOT EDIT
8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 <title>mod_ext_filter - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
19 <div id="page-header">
20 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.png" /></div>
23 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
25 <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.5</a> > <a href="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_ext_filter</h1>
29 <p><span>Available Languages: </span><a href="../en/mod/mod_ext_filter.html" title="English"> en </a> |
30 <a href="../fr/mod/mod_ext_filter.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
31 <a href="../ja/mod/mod_ext_filter.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
32 <a href="../ko/mod/mod_ext_filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
34 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Pass the response body through an external program before
35 delivery to the client</td></tr>
36 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
37 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>ext_filter_module</td></tr>
38 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_ext_filter.c</td></tr></table>
41 <p><code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> presents a simple and familiar
42 programming model for <a href="../filter.html">filters</a>. With
43 this module, a program which reads from stdin and writes to stdout
44 (i.e., a Unix-style filter command) can be a filter for
45 Apache. This filtering mechanism is much slower than using a
46 filter which is specially written for the Apache API and runs
47 inside of the Apache server process, but it does have the
48 following benefits:</p>
51 <li>the programming model is much simpler</li>
53 <li>any programming/scripting language can be used, provided
54 that it allows the program to read from standard input and
55 write to standard output</li>
57 <li>existing programs can be used unmodified as Apache
61 <p>Even when the performance characteristics are not suitable
62 for production use, <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> can be used as
63 a prototype environment for filters.</p>
66 <div id="quickview"><h3>Topics</h3>
68 <li><img alt="" src="../images/down.gif" /> <a href="#examples">Examples</a></li>
69 </ul><h3 class="directives">Directives</h3>
71 <li><img alt="" src="../images/down.gif" /> <a href="#extfilterdefine">ExtFilterDefine</a></li>
72 <li><img alt="" src="../images/down.gif" /> <a href="#extfilteroptions">ExtFilterOptions</a></li>
74 <h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&list_id=144532&product=Apache%20httpd-2&query_format=specific&order=changeddate%20DESC%2Cpriority%2Cbug_severity&component=mod_ext_filter">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&component=mod_ext_filter">Report a bug</a></li></ul><h3>See also</h3>
76 <li><a href="../filter.html">Filters</a></li>
77 <li><a href="#comments_section">Comments</a></li></ul></div>
78 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
80 <h2><a name="examples" id="examples">Examples</a></h2>
82 <h3>Generating HTML from some other type of response</h3>
83 <pre class="prettyprint lang-config"># mod_ext_filter directive to define a filter
84 # to HTML-ize text/c files using the external
85 # program /usr/bin/enscript, with the type of
86 # the result set to text/html
87 ExtFilterDefine c-to-html mode=output \
88 intype=text/c outtype=text/html \
89 cmd="/usr/bin/enscript --color -W html -Ec -o - -"
91 <Directory "/export/home/trawick/apacheinst/htdocs/c">
92 # core directive to cause the new filter to
94 SetOutputFilter c-to-html
96 # mod_mime directive to set the type of .c
99 </Directory></pre>
103 <h3>Implementing a content encoding filter</h3>
104 <p>Note: this gzip example is just for the purposes of illustration.
105 Please refer to <code class="module"><a href="../mod/mod_deflate.html">mod_deflate</a></code> for a practical
108 <pre class="prettyprint lang-config"># mod_ext_filter directive to define the external filter
109 ExtFilterDefine gzip mode=output cmd=/bin/gzip
111 <Location "/gzipped">
113 # core directive to cause the gzip filter to be
117 # mod_headers directive to add
118 # "Content-Encoding: gzip" header field
119 Header set Content-Encoding gzip
120 </Location></pre>
124 <h3>Slowing down the server</h3>
125 <pre class="prettyprint lang-config"># mod_ext_filter directive to define a filter
126 # which runs everything through cat; cat doesn't
127 # modify anything; it just introduces extra pathlength
128 # and consumes more resources
129 ExtFilterDefine slowdown mode=output cmd=/bin/cat \
130 preservescontentlength
133 # core directive to cause the slowdown filter to
134 # be run several times on output
136 SetOutputFilter slowdown;slowdown;slowdown
137 </Location></pre>
141 <h3>Using sed to replace text in the response</h3>
142 <pre class="prettyprint lang-config"># mod_ext_filter directive to define a filter which
143 # replaces text in the response
145 ExtFilterDefine fixtext mode=output intype=text/html \
146 cmd="/bin/sed s/verdana/arial/g"
149 # core directive to cause the fixtext filter to
151 SetOutputFilter fixtext
152 </Location></pre>
156 <p>You can do the same thing using <code class="module"><a href="../mod/mod_substitute.html">mod_substitute</a></code>
157 without invoking an external process.</p>
161 <h3>Tracing another filter</h3>
162 <pre class="prettyprint lang-config"># Trace the data read and written by mod_deflate
163 # for a particular client (IP 192.168.1.31)
164 # experiencing compression problems.
165 # This filter will trace what goes into mod_deflate.
166 ExtFilterDefine tracebefore \
167 cmd="/bin/tracefilter.pl /tmp/tracebefore" \
168 EnableEnv=trace_this_client
170 # This filter will trace what goes after mod_deflate.
171 # Note that without the ftype parameter, the default
172 # filter type of AP_FTYPE_RESOURCE would cause the
173 # filter to be placed *before* mod_deflate in the filter
174 # chain. Giving it a numeric value slightly higher than
175 # AP_FTYPE_CONTENT_SET will ensure that it is placed
177 ExtFilterDefine traceafter \
178 cmd="/bin/tracefilter.pl /tmp/traceafter" \
179 EnableEnv=trace_this_client ftype=21
181 <Directory "/usr/local/docs">
182 SetEnvIf Remote_Addr 192.168.1.31 trace_this_client
183 SetOutputFilter tracebefore;deflate;traceafter
184 </Directory></pre>
187 <div class="example"><h3>Here is the filter which traces the data:</h3><pre class="prettyprint lang-perl">#!/usr/local/bin/perl -w
190 open(SAVE, ">$ARGV[0]")
191 or die "can't open $ARGV[0]: $?";
193 while (<STDIN>) {
202 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
203 <div class="directive-section"><h2><a name="ExtFilterDefine" id="ExtFilterDefine">ExtFilterDefine</a> <a name="extfilterdefine" id="extfilterdefine">Directive</a></h2>
204 <table class="directive">
205 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Define an external filter</td></tr>
206 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ExtFilterDefine <var>filtername</var> <var>parameters</var></code></td></tr>
207 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
208 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
209 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_ext_filter</td></tr>
211 <p>The <code class="directive">ExtFilterDefine</code> directive defines the
212 characteristics of an external filter, including the program to
213 run and its arguments.</p>
215 <p><var>filtername</var> specifies the name of the filter being
216 defined. This name can then be used in <code class="directive"><a href="../mod/core.html#setoutputfilter">SetOutputFilter</a></code>
217 directives. It must be unique among all registered filters.
218 <em>At the present time, no error is reported by the
219 register-filter API, so a problem with duplicate names isn't
220 reported to the user.</em></p>
222 <p>Subsequent parameters can appear in any order and define the
223 external command to run and certain other characteristics. The
224 only required parameter is <code>cmd=</code>. These parameters
228 <dt><code>cmd=<var>cmdline</var></code></dt>
230 <dd>The <code>cmd=</code> keyword allows you to specify the
231 external command to run. If there are arguments after the
232 program name, the command line should be surrounded in
233 quotation marks (<em>e.g.</em>, <code>cmd="<var>/bin/mypgm</var>
234 <var>arg1</var> <var>arg2</var>"</code>.) Normal shell quoting is
235 not necessary since the program is run directly, bypassing the shell.
236 Program arguments are blank-delimited. A backslash can be used to
237 escape blanks which should be part of a program argument. Any
238 backslashes which are part of the argument must be escaped with
239 backslash themselves. In addition to the standard CGI environment
240 variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and
241 QUERY_STRING_UNESCAPED will also be set for the program.</dd>
243 <dt><code>mode=<var>mode</var></code></dt>
245 <dd>Use <code>mode=output</code> (the default) for filters which
246 process the response. Use <code>mode=input</code> for filters
247 which process the request. <code>mode=input</code> is available
248 in Apache 2.1 and later.</dd>
250 <dt><code>intype=<var>imt</var></code></dt>
252 <dd>This parameter specifies the internet media type (<em>i.e.</em>,
253 MIME type) of documents which should be filtered. By default,
254 all documents are filtered. If <code>intype=</code> is
255 specified, the filter will be disabled for documents of other
258 <dt><code>outtype=<var>imt</var></code></dt>
260 <dd>This parameter specifies the internet media type (<em>i.e.</em>,
261 MIME type) of filtered documents. It is useful when the
262 filter changes the internet media type as part of the
263 filtering operation. By default, the internet media type is
266 <dt><code>PreservesContentLength</code></dt>
268 <dd>The <code>PreservesContentLength</code> keyword specifies
269 that the filter preserves the content length. This is not the
270 default, as most filters change the content length. In the
271 event that the filter doesn't modify the length, this keyword
272 should be specified.</dd>
274 <dt><code>ftype=<var>filtertype</var></code></dt>
276 <dd>This parameter specifies the numeric value for filter type
277 that the filter should be registered as. The default value,
278 AP_FTYPE_RESOURCE, is sufficient in most cases. If the filter
279 needs to operate at a different point in the filter chain than
280 resource filters, then this parameter will be necessary. See
281 the AP_FTYPE_foo definitions in util_filter.h for appropriate
284 <dt><code>disableenv=<var>env</var></code></dt>
286 <dd>This parameter specifies the name of an environment variable
287 which, if set, will disable the filter.</dd>
289 <dt><code>enableenv=<var>env</var></code></dt>
291 <dd>This parameter specifies the name of an environment variable
292 which must be set, or the filter will be disabled.</dd>
296 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
297 <div class="directive-section"><h2><a name="ExtFilterOptions" id="ExtFilterOptions">ExtFilterOptions</a> <a name="extfilteroptions" id="extfilteroptions">Directive</a></h2>
298 <table class="directive">
299 <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>
300 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ExtFilterOptions <var>option</var> [<var>option</var>] ...</code></td></tr>
301 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>ExtFilterOptions NoLogStderr</code></td></tr>
302 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>directory</td></tr>
303 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
304 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_ext_filter</td></tr>
306 <p>The <code class="directive">ExtFilterOptions</code> directive specifies
307 special processing options for <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>.
308 <var>Option</var> can be one of</p>
311 <dt><code>LogStderr | NoLogStderr</code></dt>
313 <dd>The <code>LogStderr</code> keyword specifies that
314 messages written to standard error by the external filter
315 program will be saved in the Apache error log.
316 <code>NoLogStderr</code> disables this feature.</dd>
318 <dt><code>Onfail=[abort|remove]</code></dt>
319 <dd>Determines how to proceed if the external filter program
320 cannot be started. With <code>abort</code> (the default value)
321 the request will be aborted. With <code>remove</code>, the
322 filter is removed and the request continues without it.</dd>
325 <pre class="prettyprint lang-config">ExtFilterOptions LogStderr</pre>
328 <p>Messages written to the filter's standard error will be stored
329 in the Apache error log.</p>
333 <div class="bottomlang">
334 <p><span>Available Languages: </span><a href="../en/mod/mod_ext_filter.html" title="English"> en </a> |
335 <a href="../fr/mod/mod_ext_filter.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
336 <a href="../ja/mod/mod_ext_filter.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
337 <a href="../ko/mod/mod_ext_filter.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
338 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
339 <script type="text/javascript"><!--//--><![CDATA[//><!--
340 var comments_shortname = 'httpd';
341 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_ext_filter.html';
343 if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
344 d.write('<div id="comments_thread"><\/div>');
345 var s = d.createElement('script');
346 s.type = 'text/javascript';
348 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
349 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
352 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
354 })(window, document);
355 //--><!]]></script></div><div id="footer">
356 <p class="apache">Copyright 2017 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>
357 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
358 if (typeof(prettyPrint) !== 'undefined') {