Module mod_header_modify
Changing incoming http headers

For the impatient: Download, install, configure, have fun. RTFM (included) if it doesn't work...



Summary

This is a small Apache module that will modify, add or remove incoming http headers.


Table Of Contents

Introduction

Configuration Directives

Miscellaneous


Introduction


This module can change or remove incoming http headers and it can also add headers that weren't sent by the client. It can thus be used to manipulate the behaviour of content handlers that you don't want to (or can't) change. Another option might be to simulate various user agents, perhaps in conjuction with mod_rewrite.

Download

The module together with the documentation (i.e., this website) is available at http://www.weitz.de/files/mod_header_modify.tar.gz. The current version is 20020604.

Requirements

mod_header_modify has been tested successfully with Apache 1.3.23 on Linux 2.4.19 but I think it should work with all recent Apache releases and on all supported platforms. Please let me know about your attempts (whether successful or not) with other operating systems or other versions of Apache.

You'll need a working C compiler and its associated utilities, of course. If you've built your Apache from a source distribution you almost certainly have one... :)

Installation

There are at least two ways to install this module. Which one is appropriate depends on your Apache installation.

The easy way: If your Apache is compiled with support for dynamically loadable modules (also called DSO support), you'll just have to find out where apxs is located. Go to the directory where you unpacked the mod_header_modify.c source file and let apxs do the work:

/usr/local/apache/bin/apxs -c -i -a mod_header_modify.c
This will build mod_header_modify.so as a shared object (the -c option), install the module in the right place (-i) and add the LoadModule directive to your httpd.conf file (-a). See the apxs manual page for details about these and other command line options.

If you don't know if you have DSO support, don't worry - apxs will complain in case you haven't. You can also check beforehand by letting Apache list all compiled-in modules with httpd -l. If mod_so.c is one of them, you're lucky.

The hard way: Without DSO support you will have to rebuild Apache to use mod_header_modify. (You might consider building it with DSO support this time...) Create a new directory like, say, site underneath the src/modules directory in Apache's source tree and put the mod_header_modify.c file there. Now configure Apache with

./configure --activate-module=src/modules/site/mod_header_modify.c \
            --enable-module=header_modify
and don't forget the other configuration options that you need. You can now build and install a new httpd as usual.

Configuration Directives


HeaderModify

Syntax: HeaderModify {on,off}
Default: HeaderModify off
Context: server config, virtual host, directory, location, .htaccess

The HeaderModify directive enables or disables mod_header_modify. If it is set to off this module does no runtime processing at all.

Use this directive to disable the module instead of commenting out all directives!


HeaderModifyReplace

Syntax: HeaderModifyReplace Header Value
Default: None
Context: server config, virtual host, directory, location, .htaccess

The HeaderModifyReplace directives tell the server which headers should be replaced or created. (If the header didn't exists in the original request, it will be created. If it did exist, it will be replaced.)

Example:

HeaderModifyReplace Content-type text/xml


HeaderModifyRemove

Syntax: HeaderModifyRemove Header
Default: None
Context: server config, virtual host, directory, location, .htaccess

The HeaderModifyRemove directives tell the server which headers should be removed from the request.

Example:

HeaderModifyRemove Accept-Encoding


HeaderModifyLog

Syntax: HeaderModifyLog {on,off}
Default: HeaderModifyLog off
Context: server config, virtual host, directory, location, .htaccess

If HeaderModifyLog is set to on, header modifications will be written to the server log file with a severity level of warn.


HeaderModifyInherit

Syntax: HeaderModifyInherit {on,off}
Default: HeaderModifyInherit off
Context: server config, virtual host, directory, location, .htaccess

If this directive is set to on, the current scope will inherit the mod_header_modify settings from the parent scope by the following rules: All replacement and removal directives will be added to the parent's list of replacements and removals. All other settings will be inherited from the parent if they are not explicitly overwritten in the child's scope.

If this directive is set to off, the parent scope will be completely ignored.


Miscellaneous


Disclaimer

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Copyright

Copyright (c) 2002 Dr. Edmund Weitz. All rights reserved.
$Header: /usr/local/cvsrep/weitz.de/mod_header_modify.html,v 1.6 2007/06/04 19:27:03 edi Exp $