NAME
Apache::Filter::HTTPHeadersFixup - Manipulate Apache 2 HTTP Headers
Synopsis
# 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
PerlModule MyApache::FixupInputHTTPHeaders
PerlInputFilterHandler MyApache::FixupInputHTTPHeaders
# similar for output headers
Description
"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.
This class cannot be used as is. It has to be subclassed. Read on.
Usage
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.
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.
Debug
"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=debug apachectl start
All the tracing goes into *error_log*.
Bugs
See Also
Apache2, mod_perl, Apache::Filter
Authors
Stas Bekman
Copyright
The "Apache::Filter::HTTPHeadersFixup" module is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.