DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 10.7 Filtering Proxied Content

Problem

You want to apply some filter to proxied content, such as altering certain words.

Solution

In Apache 2.0 and later, you can use mod_ext_filter to create output filters to apply to content before it is sent to the user:

ExtFilterDefine naughtywords mode=output intype=text/html 
     cmd="/bin/sed s/darned/blasted/g"

<Proxy *>
    SetOutputFilter naughtywords
</Proxy>

Discussion

The recipe offered is a very simple-minded "naughty word" filter, replacing the naughty word "darned" with the sanitized alternate "blasted." This could be expanded to a variety of more sophisticated content modification, because the cmd argument can be any command line, such as a Perl script, or arbitrary program, which can filter the content in any way you want. All proxied content will be passed through this filter before it is delivered to the client.

Note that this recipe will work only in Apache 2.0, as the module mod_ext_filter, the SetOutputFilter directive, and the <Proxy> directive are available only in Apache 2.0.

Note also that there are ethical and legal issues surrounding techniques like this, which you may need to deal with. We don't presume to take a position on any of them. In particular, modifying proxied content that does not belong to you may be a violation of the owner's copyright and may be considered by some to be unethical. Thankfully, this is just a technical book, not a philosophical one. We can tell you how to do it, but whether you should is left to your conscience and your lawyers.

See Also

    [ Team LiB ] Previous Section Next Section