📄 mod_ext_filter.html
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-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" />
<title>mod_ext_filter - Apache 2.2 中文版参考手册</title>
</head>
<body><div id="page-header">
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">文档</a> > <a href="../index.html">版本2.2</a> > <a href="./index.html">模块</a></div>
<div id="translation-info"> <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<<a href="../translator_announcement.html#join">虚位以待</a>> | 本篇译稿完成时间:?年?月?日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_ext_filter</h1>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>使用外部程序作为过滤器</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>ext_filter_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_ext_filter.c</td></tr>
</table>
<h3>概述</h3>
<p><code class="module"><a href="../mod/mod_ext_filter.html">mod_ext_filter</a></code> presents a simple and familiar
programming model for <a href="../filter.html">过滤器</a>. 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 class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="examples" id="examples">Examples</a></h2>
<h3>Generating HTML from some other type of response</h3>
<div class="example"><p><code>
# mod_ext_filter directive to define a filter<br />
# to HTML-ize text/c files using the external<br />
# program /usr/bin/enscript, with the type of<br />
# the result set to text/html<br />
ExtFilterDefine c-to-html mode=output \<br />
<span class="indent">
intype=text/c outtype=text/html \<br />
cmd="/usr/bin/enscript --color -W html -Ec -o - -"<br />
</span>
<br />
<Directory "/export/home/trawick/apacheinst/htdocs/c"><br />
<span class="indent">
# core directive to cause the new filter to<br />
# be run on output<br />
SetOutputFilter c-to-html<br />
<br />
# mod_mime directive to set the type of .c<br />
# files to text/c<br />
AddType text/c .c<br />
<br />
# mod_ext_filter directive to set the debug<br />
# level just high enough to see a log message<br />
# per request showing the configuration in force<br />
ExtFilterOptions DebugLevel=1<br />
</span>
</Directory>
</code></p></div>
<h3>Implementing a content encoding filter</h3>
<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>
<div class="example"><p><code>
# mod_ext_filter directive to define the external filter<br />
ExtFilterDefine gzip mode=output cmd=/bin/gzip<br />
<br />
<Location /gzipped><br />
<span class="indent">
# core directive to cause the gzip filter to be<br />
# run on output<br />
SetOutputFilter gzip<br />
<br />
# mod_header directive to add<br />
# "Content-Encoding: gzip" header field<br />
Header set Content-Encoding gzip<br />
</span>
</Location>
</code></p></div>
<h3>Slowing down the server</h3>
<div class="example"><p><code>
# mod_ext_filter directive to define a filter<br />
# which runs everything through cat; cat doesn't<br />
# modify anything; it just introduces extra pathlength<br />
# and consumes more resources<br />
ExtFilterDefine slowdown mode=output cmd=/bin/cat \<br />
<span class="indent">
preservescontentlength<br />
</span>
<br />
<Location /><br />
<span class="indent">
# core directive to cause the slowdown filter to<br />
# be run several times on output<br />
#<br />
SetOutputFilter slowdown;slowdown;slowdown<br />
</span>
</Location>
</code></p></div>
<h3>Using sed to replace text in the response</h3>
<div class="example"><p><code>
# mod_ext_filter directive to define a filter which<br />
# replaces text in the response<br />
#<br />
ExtFilterDefine fixtext mode=output intype=text/html \<br />
<span class="indent">
cmd="/bin/sed s/verdana/arial/g"<br />
</span>
<br />
<Location /><br />
<span class="indent">
# core directive to cause the fixtext filter to<br />
# be run on output<br />
SetOutputFilter fixtext<br />
</span>
</Location>
</code></p></div>
<h3>Tracing another filter</h3>
<div class="example"><p><code>
# Trace the data read and written by mod_deflate<br />
# for a particular client (IP 192.168.1.31)<br />
# experiencing compression problems.<br />
# This filter will trace what goes into mod_deflate.<br />
ExtFilterDefine tracebefore \<br />
<span class="indent">
cmd="/bin/tracefilter.pl /tmp/tracebefore" \<br />
EnableEnv=trace_this_client<br />
</span>
<br />
# This filter will trace what goes after mod_deflate.<br />
# Note that without the ftype parameter, the default<br />
# filter type of AP_FTYPE_RESOURCE would cause the<br />
# filter to be placed *before* mod_deflate in the filter<br />
# chain. Giving it a numeric value slightly higher than<br />
# AP_FTYPE_CONTENT_SET will ensure that it is placed<br />
# after mod_deflate.<br />
ExtFilterDefine traceafter \<br />
<span class="indent">
cmd="/bin/tracefilter.pl /tmp/traceafter" \<br />
EnableEnv=trace_this_client ftype=21<br />
</span>
<br />
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -