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>
41 <module>mod_buffer</module>
42 <module>mod_data</module>
43 <module>mod_ratelimit</module>
44 <module>mod_reqtimeout</module>
45 <module>mod_request</module>
46 <module>mod_sed</module>
47 <module>mod_substitute</module>
50 <directive module="mod_filter">FilterChain</directive>
51 <directive module="mod_filter">FilterDeclare</directive>
52 <directive module="mod_filter">FilterProtocol</directive>
53 <directive module="mod_filter">FilterProvider</directive>
54 <directive module="mod_mime">AddInputFilter</directive>
55 <directive module="mod_mime">AddOutputFilter</directive>
56 <directive module="mod_mime">RemoveInputFilter</directive>
57 <directive module="mod_mime">RemoveOutputFilter</directive>
58 <directive module="mod_reflector">ReflectorHeader</directive>
59 <directive module="mod_ext_filter">ExtFilterDefine</directive>
60 <directive module="mod_ext_filter">ExtFilterOptions</directive>
61 <directive module="core">SetInputFilter</directive>
62 <directive module="core">SetOutputFilter</directive>
66 <p>The Filter Chain is available in Apache 2.0 and higher,
67 and enables applications to process incoming and outgoing data
68 in a highly flexible and configurable manner, regardless of
69 where the data comes from. We can pre-process incoming data,
70 and post-process outgoing data, at will. This is basically
71 independent of the traditional request processing phases.</p>
73 <img src="images/filter_arch.png" width="569" height="392" alt=
74 "Filters can be chained, in a Data Axis orthogonal to request processing"
77 <p>Some examples of filtering in the standard Apache distribution are:</p>
79 <li><module>mod_include</module>, implements server-side includes.</li>
80 <li><module>mod_ssl</module>, implements SSL encryption (https).</li>
81 <li><module>mod_deflate</module>, implements compression/decompression on the fly.</li>
82 <li><module>mod_charset_lite</module>, transcodes between different character sets.</li>
83 <li><module>mod_ext_filter</module>, runs an external program as a filter.</li>
85 <p>Apache also uses a number of filters internally to perform
86 functions like chunking and byte-range handling.</p>
88 <p>A wider range of applications are implemented by third-party filter
89 modules available from <a
90 href="http://modules.apache.org/">modules.apache.org</a> and
91 elsewhere. A few of these are:</p>
94 <li>HTML and XML processing and rewriting</li>
95 <li>XSLT transforms and XIncludes</li>
96 <li>XML Namespace support</li>
97 <li>File Upload handling and decoding of HTML Forms</li>
98 <li>Image processing</li>
99 <li>Protection of vulnerable applications such as PHP scripts</li>
100 <li>Text search-and-replace editing</li>
105 <title>Smart Filtering</title>
107 <img src="images/mod_filter_new.png" width="423" height="331"
108 alt="Smart filtering applies different filter providers according to the state of request processing"/>
110 <p><module>mod_filter</module>, included in Apache 2.1 and later,
111 enables the filter chain to be configured dynamically at run time.
112 So for example you can set up a proxy to rewrite
113 HTML with an HTML filter and JPEG images with a completely
114 separate filter, despite the proxy having no prior information
115 about what the origin server will send. This works by using a
116 filter harness, that dispatches to different providers according
117 to the actual contents at runtime. Any filter may be either
118 inserted directly in the chain and run unconditionally, or
119 used as a provider and inserted dynamically. For example,</p>
121 <li>an HTML processing filter will only run if the content is
122 text/html or application/xhtml+xml</li>
123 <li>A compression filter will only run if the input is a
124 compressible type and not already compressed</li>
125 <li>A charset conversion filter will be inserted if a text
126 document is not already in the desired charset</li>
130 <section id="service">
132 <title>Exposing Filters as an HTTP Service</title>
133 <p>Filters can be used to process content originating from the client in
134 addition to processing content originating on the server using the
135 <module>mod_reflector</module> module.</p>
137 <p><module>mod_reflector</module> accepts POST requests from clients, and reflects
138 the content request body received within the POST request back in the response,
139 passing through the output filter stack on the way back to the client.</p>
141 <p>This technique can be used as an alternative to a web service running within
142 an application server stack, where an output filter provides the transformation
143 required on the request body. For example, the <module>mod_deflate</module>
144 module might be used to provide a general compression service, or an image
145 transformation filter might be turned into an image transformation service.</p>
150 <title>Using Filters</title>
151 <p>There are two ways to use filtering: Simple and Dynamic.
152 In general, you should use one or the other; mixing them can
153 have unexpected consequences (although simple Input filtering
154 can be mixed freely with either simple or dynamic Output filtering).</p>
155 <p>The Simple Way is the only way to configure input filters, and is
156 sufficient for output filters where you need a static filter chain.
157 Relevant directives are
158 <directive module="core">SetInputFilter</directive>,
159 <directive module="core">SetOutputFilter</directive>,
160 <directive module="mod_mime">AddInputFilter</directive>,
161 <directive module="mod_mime">AddOutputFilter</directive>,
162 <directive module="mod_mime">RemoveInputFilter</directive>, and
163 <directive module="mod_mime">RemoveOutputFilter</directive>.</p>
165 <p>The Dynamic Way enables both static and flexible, dynamic configuration
166 of output filters, as discussed in the <module>mod_filter</module> page.
167 Relevant directives are
168 <directive module="mod_filter">FilterChain</directive>,
169 <directive module="mod_filter">FilterDeclare</directive>, and
170 <directive module="mod_filter">FilterProvider</directive>.</p>
172 <p>One further directive <directive
173 module="mod_filter">AddOutputFilterByType</directive> is still supported,
174 but deprecated. Use dynamic configuration instead.</p>