1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <manualpage metafile="filter.xml.meta">
25 <title>Filters</title>
28 <p>This document describes the use of filters in Apache.</p>
32 <title>Filtering in Apache 2</title>
35 <module>mod_filter</module>
36 <module>mod_deflate</module>
37 <module>mod_ext_filter</module>
38 <module>mod_include</module>
39 <module>mod_charset_lite</module>
40 <module>mod_reflector</module>
43 <directive module="mod_filter">FilterChain</directive>
44 <directive module="mod_filter">FilterDeclare</directive>
45 <directive module="mod_filter">FilterProtocol</directive>
46 <directive module="mod_filter">FilterProvider</directive>
47 <directive module="mod_mime">AddInputFilter</directive>
48 <directive module="mod_mime">AddOutputFilter</directive>
49 <directive module="mod_mime">RemoveInputFilter</directive>
50 <directive module="mod_mime">RemoveOutputFilter</directive>
51 <directive module="mod_reflector">ReflectorHeader</directive>
52 <directive module="mod_ext_filter">ExtFilterDefine</directive>
53 <directive module="mod_ext_filter">ExtFilterOptions</directive>
54 <directive module="core">SetInputFilter</directive>
55 <directive module="core">SetOutputFilter</directive>
59 <p>The Filter Chain is available in Apache 2.0 and higher,
60 and enables applications to process incoming and outgoing data
61 in a highly flexible and configurable manner, regardless of
62 where the data comes from. We can pre-process incoming data,
63 and post-process outgoing data, at will. This is basically
64 independent of the traditional request processing phases.</p>
66 <img src="images/filter_arch.png" width="569" height="392" alt=
67 "Filters can be chained, in a Data Axis orthogonal to request processing"
70 <p>Some examples of filtering in the standard Apache distribution are:</p>
72 <li><module>mod_include</module>, implements server-side includes.</li>
73 <li><module>mod_ssl</module>, implements SSL encryption (https).</li>
74 <li><module>mod_deflate</module>, implements compression/decompression on the fly.</li>
75 <li><module>mod_charset_lite</module>, transcodes between different character sets.</li>
76 <li><module>mod_ext_filter</module>, runs an external program as a filter.</li>
78 <p>Apache also uses a number of filters internally to perform
79 functions like chunking and byte-range handling.</p>
81 <p>A wider range of applications are implemented by third-party filter
82 modules available from <a
83 href="http://modules.apache.org/">modules.apache.org</a> and
84 elsewhere. A few of these are:</p>
87 <li>HTML and XML processing and rewriting</li>
88 <li>XSLT transforms and XIncludes</li>
89 <li>XML Namespace support</li>
90 <li>File Upload handling and decoding of HTML Forms</li>
91 <li>Image processing</li>
92 <li>Protection of vulnerable applications such as PHP scripts</li>
93 <li>Text search-and-replace editing</li>
98 <title>Smart Filtering</title>
100 <img src="images/mod_filter_new.png" width="423" height="331"
101 alt="Smart filtering applies different filter providers according to the state of request processing"/>
103 <p><module>mod_filter</module>, included in Apache 2.1 and later,
104 enables the filter chain to be configured dynamically at run time.
105 So for example you can set up a proxy to rewrite
106 HTML with an HTML filter and JPEG images with a completely
107 separate filter, despite the proxy having no prior information
108 about what the origin server will send. This works by using a
109 filter harness, that dispatches to different providers according
110 to the actual contents at runtime. Any filter may be either
111 inserted directly in the chain and run unconditionally, or
112 used as a provider and inserted dynamically. For example,</p>
114 <li>an HTML processing filter will only run if the content is
115 text/html or application/xhtml+xml</li>
116 <li>A compression filter will only run if the input is a
117 compressible type and not already compressed</li>
118 <li>A charset conversion filter will be inserted if a text
119 document is not already in the desired charset</li>
123 <section id="service">
125 <title>Exposing Filters as an HTTP Service</title>
126 <p>Filters can be used to process content originating from the client in
127 addition to processing content originating on the server using the
128 <module>mod_reflector</module> module.</p>
130 <p><module>mod_reflector</module> accepts POST requests from clients, and reflects
131 the content request body received within the POST request back in the response,
132 passing through the output filter stack on the way back to the client.</p>
134 <p>This technique can be used as an alternative to a web service running within
135 an application server stack, where an output filter provides the transformation
136 required on the request body. For example, the <module>mod_deflate</module>
137 module might be used to provide a general compression service, or an image
138 transformation filter might be turned into an image transformation service.</p>
143 <title>Using Filters</title>
144 <p>There are two ways to use filtering: Simple and Dynamic.
145 In general, you should use one or the other; mixing them can
146 have unexpected consequences (although simple Input filtering
147 can be mixed freely with either simple or dynamic Output filtering).</p>
148 <p>The Simple Way is the only way to configure input filters, and is
149 sufficient for output filters where you need a static filter chain.
150 Relevant directives are
151 <directive module="core">SetInputFilter</directive>,
152 <directive module="core">SetOutputFilter</directive>,
153 <directive module="mod_mime">AddInputFilter</directive>,
154 <directive module="mod_mime">AddOutputFilter</directive>,
155 <directive module="mod_mime">RemoveInputFilter</directive>, and
156 <directive module="mod_mime">RemoveOutputFilter</directive>.</p>
158 <p>The Dynamic Way enables both static and flexible, dynamic configuration
159 of output filters, as discussed in the <module>mod_filter</module> page.
160 Relevant directives are
161 <directive module="mod_filter">FilterChain</directive>,
162 <directive module="mod_filter">FilterDeclare</directive>, and
163 <directive module="mod_filter">FilterProvider</directive>.</p>
165 <p>One further directive <directive
166 module="mod_filter">AddOutputFilterByType</directive> is still supported,
167 but deprecated. Use dynamic configuration instead.</p>