2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.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 <modulesynopsis metafile="mod_sed.xml.meta">
26 <description>Filter Input (request) and Output (response) content using <code>sed</code> syntax</description>
27 <status>Experimental</status>
28 <sourcefile>mod_sed.c sed0.c sed1.c regexp.c regexp.h sed.h</sourcefile>
29 <identifier>sed_module</identifier>
30 <compatibility>Available in Apache 2.3 and later</compatibility>
34 <module>mod_sed</module> is an in-process content filter. The <module>mod_sed</module> filter implements the <code>sed</code> editing
35 commands implemented by the Solaris 10 <code>sed</code>
36 program as described in the <a href="http://www.gnu.org/software/sed/manual/sed.txt">manual
37 page</a>. However, unlike <code>sed</code>, <module>mod_sed</module> doesn't take data from
39 input. Instead, the filter acts on the entity data sent between client and
40 server. <module>mod_sed</module> can be used as an input or output filter. <module>mod_sed</module> is a
41 content filter, which means that it cannot be used to modify client or
45 The <module>mod_sed</module> output filter accepts a chunk of data, executes the <code>sed</code> scripts on the data, and generates the output which is passed to the next filter in the chain.
49 The <module>mod_sed</module> input filter reads the data from the next filter in the chain, executes the <code>sed</code> scripts, and returns the generated data to the caller filter in the filter chain.
53 Both the input and output filters only process the data if newline characters are seen in the content. At the end of the data, the rest of the data is treated as the last line.
56 <p>A tutorial article on <module>mod_sed</module>, and why it is more powerful than simple
57 string or regular expression search and replace, is available <a
58 href="https://blogs.oracle.com/basant/entry/using_mod_sed_to_filter">on
59 the author's blog</a>.</p>
63 <section id="sampleconf"><title>Sample Configuration</title>
64 <example><title>Adding an output filter </title>
65 <highlight language="config">
66 # In the following example, the sed filter will change the string
67 # "monday" to "MON" and the string "sunday" to SUN in html documents
68 # before sending to the client.
69 <Directory "/var/www/docs/sed">
70 AddOutputFilter Sed html
71 OutputSed "s/monday/MON/g"
72 OutputSed "s/sunday/SUN/g"
77 <example><title>Adding an input filter </title>
78 <highlight language="config">
79 # In the following example, the sed filter will change the string
80 # "monday" to "MON" and the string "sunday" to SUN in the POST data
82 <Directory "/var/www/docs/sed">
83 AddInputFilter Sed php
84 InputSed "s/monday/MON/g"
85 InputSed "s/sunday/SUN/g"
90 <section id="sed_commands"><title>Sed Commands</title>
92 Complete details of the <code>sed</code> command can be found from the
93 <a href="http://www.gnu.org/software/sed/manual/sed.txt">sed manual
97 <dt><code>b</code></dt>
98 <dd>Branch to the label specified (similar to goto).</dd>
99 <dt><code>h</code></dt>
100 <dd>Copy the current line to the hold buffer.</dd>
101 <dt><code>H</code></dt>
102 <dd>Append the current line to the hold buffer.</dd>
103 <dt><code>g</code></dt>
104 <dd>Copy the hold buffer to the current line.</dd>
105 <dt><code>G</code></dt>
106 <dd>Append the hold buffer to the current line.</dd>
107 <dt><code>x</code></dt>
108 <dd>Swap the contents of the hold buffer and the current line.</dd>
113 <name>OutputSed</name>
114 <description>Sed command for filtering response content</description>
115 <syntax>OutputSed <var>sed-command</var></syntax>
116 <contextlist><context>directory</context><context>.htaccess</context>
120 <p>The <directive>OutputSed</directive> directive specifies the <code>sed</code>
121 command to execute on the response.
127 <name>InputSed</name>
128 <description>Sed command to filter request data (typically <code>POST</code> data)</description>
129 <syntax>InputSed <var>sed-command</var></syntax>
130 <contextlist><context>directory</context><context>.htaccess</context>
134 <p>The <directive>InputSed</directive> directive specifies the <code>sed</code> command
135 to execute on the request data e.g., <code>POST</code> data.