Summary

mod_ext_filter 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:

the programming model is much simpler

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

existing programs can be used unmodified as Apache
filters

Even when the performance characteristics are not suitable
for production use, mod_ext_filter can be used as
a prototype environment for filters.

# 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

The ExtFilterDefine directive defines the
characteristics of an external filter, including the program to
run and its arguments.

filtername 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.
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.

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

cmd=cmdline

The cmd= 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., cmd="/bin/mypgmarg1arg2".) 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.

mode=mode

Use mode=output (the default) for filters which
process the response. Use mode=input for filters
which process the request. mode=input is available
in Apache 2.1 and later.

intype=imt

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

outtype=imt

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.

PreservesContentLength

The PreservesContentLength 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.

ftype=filtertype

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.

disableenv=env

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

enableenv=env

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

The ExtFilterOptions directive specifies
special processing options for mod_ext_filter.
Option can be one of

DebugLevel=n

The DebugLevel keyword allows you to specify
the level of debug messages generated by
mod_ext_filter. By default, no debug messages
are generated. This is equivalent to
DebugLevel=0. 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 mod_ext_filter.c.

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

LogStderr | NoLogStderr

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

Onfail=[abort|remove] (new in httpd version 2.2.12).

Determines how to proceed if the external filter program
cannot be started. With abort (the default value)
the request will be aborted. With remove, the
filter is removed and the request continues without it.

Example

ExtFilterOptions LogStderr DebugLevel=0

Messages written to the filter's standard error will be stored
in the Apache error log. No debug messages will be generated by
mod_ext_filter.

Notice: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 mailing lists.