<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              This file is generated from xml source: DO NOT EDIT
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      --><title>mod_ext_filter - Apache HTTP Server</title><link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="../images/favicon.ico" rel="shortcut icon" /></head><body><div id="page-header"><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><p class="apache">Apache HTTP Server Version 2.0</p><img alt="" src="../images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div><div id="path"><a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs-project/">Documentation</a> &gt; <a href="../">Version 2.0</a> &gt; <a href="./">Modules</a></div><div id="page-content"><div id="preamble"><h1>Apache Module mod_ext_filter</h1><table class="module"><tr><th><a href="module-dict.html#Description">Description:
                  </a></th><td>Pass the response body
    through an external program before delivery to the
    client</td></tr><tr><th><a href="module-dict.html#Status">Status:
                  </a></th><td>Experimental</td></tr><tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:
                  </a></th><td>ext_filter_module</td></tr><tr><th><a href="module-dict.html#SourceFile">Source File:
                  </a></th><td>mod_ext_filter.c</td></tr></table><h3>Summary</h3>
    <p>This is an <strong>experimental</strong> module and should
    be used with care. Test your <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>
    configuration carefully to ensure that it performs the desired
    function. You may wish to review <a href="../filter.html">
    this information</a> for background on the Apache filtering 
    model.</p>

    <p><code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> presents a simple and familiar
    programming model for filters. With this module, a program
    which reads from stdin and writes to stdout (i.e., a Unix-style
    filter command) can be a filter for Apache. This filtering
    mechanism is much slower than using a filter which is specially
    written for the Apache API and runs inside of the Apache server
    process, but it does have the following benefits:</p>

    <ul>
      <li>the programming model is much simpler</li>

      <li>any programming/scripting language can be used, provided
      that it allows the program to read from standard input and
      write to standard output</li>

      <li>existing programs can be used unmodified as Apache
      filters</li>
    </ul>

    <p>Even when the performance characteristics are not suitable
    for production use, <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> can be used as
    a prototype environment for filters.</p>
</div><div id="quickview"><h3 class="directives">Directives</h3><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#extfilterdefine">ExtFilterDefine</a></li><li><img alt="" src="../images/down.gif" /> <a href="#extfilteroptions">ExtFilterOptions</a></li></ul><h3>Topics</h3><ul id="topics"><li><img alt="" src="../images/down.gif" /> Examples</li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2>Examples</h2>

<h3>Generating HTML from some other type of response</h3>
<div class="example"><pre>
# mod_ext_filter directive to define a filter to HTML-ize text/c files 
# using the external program /usr/bin/enscript, with the type of the 
# result set to text/html
ExtFilterDefine c-to-html mode=output intype=text/c outtype=text/html \
                cmd="/usr/bin/enscript --color -W html -Ec -o - -"

&lt;Directory "/export/home/trawick/apacheinst/htdocs/c"&gt;

# core directive to cause the new filter to be run on output
SetOutputFilter c-to-html

# mod_mime directive to set the type of .c files to text/c
AddType text/c .c

# mod_ext_filter directive to set the debug level just high 
# enough to see a log message per request showing the configuration
# in force
ExtFilterOptions DebugLevel=1

&lt;/Directory&gt;
</pre></div>


<h3>Implementing a content encoding filter</h3>
<div class="example"><pre>
# mod_ext_filter directive to define the external filter
ExtFilterDefine gzip mode=output cmd=/bin/gzip

&lt;Location /gzipped&gt;

# core directive to cause the gzip filter to be run on output
SetOutputFilter gzip

# mod_header directive to add "Content-Encoding: gzip" header field
Header set Content-Encoding gzip

&lt;/Location&gt;
</pre></div>

  <p>Note: this gzip example is just for the purposes of illustration.
  Please refer to <code class="module"><a href="../mod/mod_deflate.html">mod_deflate</a></code> for a practical
  implementation.</p>


<h3>Slowing down the server</h3>
<div class="example"><pre>
# mod_ext_filter directive to define a filter which runs everything 
# through cat; cat doesn't modify anything; it just introduces extra
# pathlength and consumes more resources
ExtFilterDefine slowdown mode=output cmd=/bin/cat preservescontentlength

&lt;Location /&gt;

# core directive to cause the slowdown filter to be run several times on 
# output
SetOutputFilter slowdown slowdown slowdown

&lt;/Location&gt;
</pre></div>


<h3>Using sed to replace text in the response</h3>
<div class="example"><pre>
# mod_ext_filter directive to define a filter which replaces text in
# the response
ExtFilterDefine fixtext mode=output cmd="/bin/sed s/verdana/arial/g" intype=text/html

&lt;Location /&gt;

# core directive to cause the fixtext filter to be run on output
# output
SetOutputFilter fixtext

&lt;/Location&gt;
</pre></div>


<h3>Tracing another filter</h3>
<div class="example"><pre>
# Trace the data read and written by mod_deflate for a particular
# client (IP 192.168.1.31) experiencing compression problems.
# This filter will trace what goes into mod_deflate.
ExtFilterDefine tracebefore cmd="/bin/tracefilter.pl /tmp/tracebefore" \
  EnableEnv=trace_this_client
# This filter will trace what goes after mod_deflate.  Note that without
# the ftype parameter, the default filter type of AP_FTYPE_RESOURCE would
# cause the filter to be placed *before* mod_deflate in the filter 
# chain.  Giving it a numeric value slightly higher than 
# AP_FTYPE_CONTENT_SET will ensure that it is placed after mod_deflate.
ExtFilterDefine traceafter  cmd="/bin/tracefilter.pl /tmp/traceafter" \
  EnableEnv=trace_this_client ftype=21

&lt;Directory /usr/local/docs&gt;
  SetEnvIf Remote_Addr 192.168.1.31 trace_this_client
  SetOutputFilter tracebefore;deflate;traceafter
&lt;/Directory&gt;
</pre></div>

<div class="example"><h3>Here is the filter which traces the data:</h3><pre>
#!/usr/local/bin/perl -w

use strict;

open(SAVE, "&gt;$ARGV[0]") or die "can't open $ARGV[0]: $?";

while (&lt;STDIN&gt;)
{
  print SAVE $_;
  print $_;
}

close(SAVE);
</pre></div>


</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="ExtFilterDefine" id="ExtFilterDefine">ExtFilterDefine</a> <a name="extfilterdefine" id="extfilterdefine">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
              </a></th><td /></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
              </a></th><td>ExtFilterDefine <em>filtername</em> <em>parameters</em></td></tr><tr><th><a href="directive-dict.html#Context">Context:
              </a></th><td>server config</td></tr><tr><th><a href="directive-dict.html#Status">Status:
              </a></th><td>Experimental</td></tr><tr><th><a href="directive-dict.html#Module">Module:
              </a></th><td>mod_ext_filter</td></tr></table>
    <p>The <code class="directive">ExtFilterDefine</code> directive defines the
    characteristics of an external filter, including the program to
    run and its arguments.</p>

    <p><em>filtername</em> specifies the name of the filter being
    defined. This name can then be used in SetOutputFilter
    directives. It must be unique among all registered filters.
    <em>At the present time, no error is reported by the
    register-filter API, so a problem with duplicate names isn't
    reported to the user.</em></p>

    <p>Subsequent parameters can appear in any order and define the
    external command to run and certain other characteristics. The
    only required parameter is <em>cmd=</em>. These parameters
    are:</p>

    <dl>
      <dt>cmd=<em>cmdline</em></dt>

      <dd>The <code>cmd=</code> keyword allows you to specify the
      external command to run. If there are arguments after the
      program name, the command line should be surrounded in
      quotation marks (e.g., <em>cmd="/bin/mypgm arg1 arg2"</em>.
      Normal shell quoting is not necessary since the program is
      run directly, bypassing the shell.  Program arguments are
      blank-delimited.  A backslash can be used to escape blanks 
      which should be part of a program argument.  Any backslashes
      which are part of the argument must be escaped with backslash
      themselves.  In addition to the standard CGI environment 
      variables, DOCUMENT_URI, DOCUMENT_PATH_INFO, and 
      QUERY_STRING_UNESCAPED will also be set for the program.</dd>

      <dt>mode=<em>mode</em></dt>

      <dd><em>mode</em> should be <em>output</em> for now (the
      default). In the future, <em>mode=input</em> will be used to
      specify a filter for request bodies.</dd>

      <dt>intype=<em>imt</em></dt>

      <dd>This parameter specifies the internet media type (i.e.,
      MIME type) of documents which should be filtered. By default,
      all documents are filtered. If <code>intype=</code> is
      specified, the filter will be disabled for documents of other
      types.</dd>

      <dt>outtype=<em>imt</em></dt>

      <dd>This parameter specifies the internet media type (i.e.,
      MIME type) of filtered documents. It is useful when the
      filter changes the internet media type as part of the
      filtering operation. By default, the internet media type is
      unchanged.</dd>

      <dt>PreservesContentLength</dt>

      <dd>The <code>PreservesContentLength</code> keyword specifies
      that the filter preserves the content length. This is not the
      default, as most filters change the content length. In the
      event that the filter doesn't modify the length, this keyword
      should be specified.</dd>

      <dt>ftype=<em>filtertype</em></dt>

      <dd>This parameter specifies the numeric value for filter type
      that the filter should be registered as.  The default value,
      AP_FTYPE_RESOURCE, is sufficient in most cases.  If the filter
      needs to operate at a different point in the filter chain than
      resource filters, then this parameter will be necessary.  See
      the AP_FTYPE_foo definitions in util_filter.h for appropriate
      values.</dd>

      <dt>disableenv=<em>env</em></dt>

      <dd>This parameter specifies the name of an environment variable
      which, if set, will disable the filter.</dd>

      <dt>enableenv=<em>env</em></dt>

      <dd>This parameter specifies the name of an environment variable
      which must be set, or the filter will be disabled.</dd>

    </dl>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="directive-section"><h2><a name="ExtFilterOptions" id="ExtFilterOptions">ExtFilterOptions</a> <a name="extfilteroptions" id="extfilteroptions">Directive</a></h2><table class="directive"><tr><th><a href="directive-dict.html#Description">Description: 
              </a></th><td /></tr><tr><th><a href="directive-dict.html#Syntax">Syntax:
              </a></th><td>ExtFilterOptions
    <em>option</em> [<em>option</em>] ...</td></tr><tr><th><a href="directive-dict.html#Default">Default: 
              </a></th><td><code>ExtFilterOptions DebugLevel=0 NoLogStderr</code></td></tr><tr><th><a href="directive-dict.html#Context">Context:
              </a></th><td>directory</td></tr><tr><th><a href="directive-dict.html#Status">Status:
              </a></th><td>Experimental</td></tr><tr><th><a href="directive-dict.html#Module">Module:
              </a></th><td>mod_ext_filter</td></tr></table>
    <p>The <code class="directive">ExtFilterOptions</code> directive specifies
    special processing options for <code>mod_ext_filter</code>.
    <em>Option</em> can be one of</p>

    <dl>
      <dt>DebugLevel=<em>n</em></dt>

      <dd>
        The <code>DebugLevel</code> keyword allows you to specify
        the level of debug messages generated by
        <code>mod_ext_filter</code>. By default, no debug messages
        are generated. This is equivalent to
        <code>DebugLevel=0</code>. With higher numbers, more debug
        messages are generated, and server performance will be
        degraded. The actual meanings of the numeric values are
        described with the definitions of the DBGLVL_ constants
        near the beginning of <code>mod_ext_filter.c</code>. 

        <p>Note: The core directive LogLevel should be used to
        cause debug messages to be stored in the Apache error
        log.</p>
      </dd>

      <dt>LogStderr | NoLogStderr</dt>

      <dd>The <code>LogStderr</code> keyword specifies that
      messages written to standard error by the external filter
      program will be saved in the Apache error log.
      <code>NoLogStderr</code> disables this feature.</dd>
    </dl>

<div class="example"><h3>Example</h3><p><code>
    ExtFilterOptions  LogStderr DebugLevel=0
</code></p></div>

    <p>Messages written to the filter's standard error will be stored
    in the Apache error log. No debug messages will be generated by
    <code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code>. </p>
</div></div><div id="footer"><p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p><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></body></html>