| 描述: | 在传递给客户端之前,将响应主体通过外部程序传递 |
|---|---|
| 状态: | 延期 |
| 模块标识符: | ext_filter_module |
| 源文件: | mod_ext_filter.c |
mod_ext_filter提出了一个简单而熟悉的过滤器编程模型。使用此模块,从stdin读取并写入stdout的程序(即Unix样式的filter命令)可以成为Apache的过滤器。与使用专门为Apache API编写并在Apache服务器进程内部运行的过滤器相比,此过滤机制要慢得多,但是它确实具有以下好处:
即使性能特征不适合生产使用,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 -"
<Directory "/export/home/trawick/apacheinst/htdocs/c">
# 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
</Directory>
注意:此gzip示例仅用于说明目的。请参阅以mod_deflate获取实际的实现。
# mod_ext_filter directive to define the external filter
ExtFilterDefine gzip mode=output cmd=/bin/gzip
<Location "/gzipped">
# 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
</Location>
# 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
<Location "/">
# core directive to cause the slowdown filter to
# be run several times on output
#
SetOutputFilter slowdown;slowdown;slowdown
</Location>
# 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"
<Location "/">
# core directive to cause the fixtext filter to
# be run on output
SetOutputFilter fixtext
</Location>
您可以使用相同的方法进行操作mod_substitute
而无需调用外部进程。
# 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
<Directory "/usr/local/docs">
SetEnvIf Remote_Addr 192.168.1.31 trace_this_client
SetOutputFilter tracebefore;deflate;traceafter
</Directory>
#!/usr/local/bin/perl -w
use strict;
open(SAVE, ">$ARGV[0]")
or die "can't open $ARGV[0]: $?";
while (<STDIN>) {
print SAVE $_;
print $_;
}
close(SAVE);
| 描述: | 定义一个外部过滤器 |
|---|---|
| 句法: | ExtFilterDefine filtername parameters |
| 内容: | 服务器配置 |
| 状态: | 延期 |
| 模块: | mod_ext_filter |
该ExtFilterDefine指令定义了外部过滤器的特征,包括要运行的程序及其参数。
filtername指定要定义的过滤器的名称。然后可以在SetOutputFilter
指令中使用该名称。在所有已注册的过滤器中,它必须是唯一的。
目前,寄存器过滤器API尚未报告任何错误,因此不会向用户报告名称重复的问题。
后续参数可以按任何顺序出现,并定义要运行的外部命令和某些其他特征。唯一需要的参数是cmd=。这些参数是:
cmd=cmdlinecmd=关键字允许您指定的外部命令来运行。如果程序名称后面有参数,则命令行应使用引号引起来(例如,。)。由于程序直接运行,绕过了外壳程序,因此不需要常规的外壳程序引号。程序参数用空格分隔。反斜杠可用于转义空格,空格应作为程序参数的一部分。作为参数一部分的任何反斜杠都必须使用反斜杠自己进行转义。除了标准的CGI环境变量外,还将为程序设置DOCUMENT_URI,DOCUMENT_PATH_INFO和QUERY_STRING_UNESCAPED。cmd="/bin/mypgm
arg1 arg2"mode=modemode=output(默认)过滤器来处理响应。使用mode=input了其处理请求的过滤器。 mode=input在Apache 2.1及更高版本中可用。intype=imtintype=指定,则将禁用其他类型文档的过滤器。outtype=imtPreservesContentLengthPreservesContentLength关键字指定的过滤器保留内容长度。这不是默认设置,因为大多数过滤器都会更改内容长度。如果过滤器未修改长度,则应指定此关键字。ftype=filtertypedisableenv=envenableenv=env| 描述: | 配置mod_ext_filter选项 |
|---|---|
| 句法: | ExtFilterOptions option [option] ... |
| 默认: | ExtFilterOptions NoLogStderr |
| 内容: | 目录 |
| 状态: | 延期 |
| 模块: | mod_ext_filter |
该ExtFilterOptions指令规定了特殊处理选项mod_ext_filter。
选项可以是以下之一
LogStderr | NoLogStderrLogStderr关键字指定由外部过滤器程序写到标准的错误消息将被保存在Apache的错误日志。
NoLogStderr禁用此功能。Onfail=[abort|remove]abort(默认值),请求将被中止。使用remove,将删除过滤器,并且在没有过滤器的情况下继续进行请求。ExtFilterOptions LogStderr
写入过滤器标准错误的消息将存储在Apache错误日志中。