Apache::Filter::HTTPHeadersFixup - Manipulate Apache 2 HTTP Headers
# MyApache/FixupInputHTTPHeaders.pm package MyApache::FixupInputHTTPHeaders; use strict; use warnings FATAL => 'all'; use base qw(Apache::Filter::HTTPHeadersFixup); sub manip { my ($class, $ra_headers) = @_; # modify a header for (@$ra_headers) { s/^(Foo).*/$1: Moahaha/; } # push header (don't forget "\n"!) push @$ra_headers, "Bar: MidBar\n"; } 1; # httpd.conf <VirtualHost Zoot> PerlModule MyApache::FixupInputHTTPHeaders PerlInputFilterHandler MyApache::FixupInputHTTPHeaders </VirtualHost> # similar for output headers
Apache::Filter::HTTPHeadersFixup is a super class which provides an easy way to manipulate HTTP headers without invoking any mod_perl HTTP callbacks. This is accomplished by using input and output connection filters.
Apache::Filter::HTTPHeadersFixup
This class cannot be used as is. It has to be subclassed. Read on.
A new class inheriting from Apache::Filter::HTTPHeadersFixup needs to be created. That class needs to include a single function manip(). This function is invoked with two arguments, the package it was invoked from and a reference to an array of headers, each terminated with a new line.
manip()
That function can manipulate the values in that hash. It shouldn't return anything. That means you can't assign to the reference itself or the headers will be lost.
Now you can modify, add or remove headers.
The function works indentically for input and output HTTP headers.
See the Synopsis section for an example and more examples can be seen in the test suite.
Apache::Filter::HTTPHeadersFixup includes internal tracing calls, which make it easy to debug the parsing of the headers. For example to run a test with tracing enabled do:
% t/TEST -trace=debug -v manip/out_append
Or you can set the APACHE_TEST_TRACE_LEVEL to debug at the server startup:
APACHE_TEST_TRACE_LEVEL
APACHE_TEST_TRACE_LEVEL=debug apachectl start
All the tracing goes into error_log.
Apache2, mod_perl, Apache::Filter
Stas Bekman <stas@stason.org>
The Apache::Filter::HTTPHeadersFixup module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Apache::Filter::HTTPHeadersFixup, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache::Filter::HTTPHeadersFixup
CPAN shell
perl -MCPAN -e shell install Apache::Filter::HTTPHeadersFixup
For more information on module installation, please visit the detailed CPAN module installation guide.