Apache Module mod_ext_filter
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 - -"
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 define the external filter ExtFilterDefine gzip mode=output cmd=/bin/gzip
core directive to cause the gzip filter to be
run on output SetOutputFilter gzip
mod_headers directive to add
"Content-Encoding: gzip" header field Header set Content-Encoding gzip
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
core directive to cause the slowdown filter to
be run several times on output
SetOutputFilter slowdown;slowdown;slowdown
mod_ext_filter directive to define a filter which
replaces text in the response
ExtFilterDefine fixtext mode=output intype=text/html \ cmd="/bin/sed s/verdana/arial/g"
core directive to cause the fixtext filter to
be run on output SetOutputFilter fixtext
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 SetEnvIf Remote_Addr 19
presents a simple and familiar programming model for modextfilterfilters. 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:
Even when the performance characteristics are not suitable for production use,
can be used as a prototype environment for filters.modextfilter
#!/usr/local/bin/perl -w use strict; open(SAVE, ">$ARGV[0]") or die "can't open $ARGV[0]: $?"; while (
filtername specifies the name of the filter being defined. This name can then be used in
directives. It must be unique among all registered filters. SetOutputFilterAt 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=
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 (cmd="/bin/mypgm arg1 arg2"
.) 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, DOCUMENTURI, DOCUMENTPATHINFO, and QUERYSTRING_UNESCAPED will also be set for the program.mode=mode
for filters which process the request. mode=input
is specified, the filter will be disabled for documents of other types.outtype=imt
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
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]
, the filter is removed and the request continues without it.ExtFilterOptions LogStderr
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
Apache Module mod_ext_filter
Available Languages: en | fr | ja | ko
Examples
Note: this gzip example is just for the purposes of illustration. Please refer to mod_deflate for a practical implementation.
ExtFilterDefine Directive
The ExtFilterDefine directive defines the characteristics of an external filter, including the program to run and its arguments.
ExtFilterOptions Directive
The ExtFilterOptions directive specifies special processing options for mod_ext_filter. Option can be one of