You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Stas Bekman <st...@stason.org> on 2003/10/08 08:25:37 UTC
[mp2 module rfc] Apache::Filter::HTTPHeadersManip
As I was writing for Chris the test that manipulates HTTP headers and seeing
that it's not trivial for the end users (due to the http_in core httpd
filter's implementation), I've realized that the functionality of manipulating
HTTP headers can be abstracted, letting the end user do very little work. So I
came up with Apache::Filter::HTTPHeadersManip which you can try
http://apache.org/~stas/Apache-Filter-HTTPHeadersManip-0.01.tar.gz
While working on this code I have discovered a bug in modperl-1.99_10, which
is now fixed in cvs. Therefore to try this module you need the cvs version or
1.99_11 (which is not released at the moment). The module comes with a full
test suite, so you can see it in action.
To write a new header manipulator all you need to do is to subclass this
package and provide a simple function that manipulates the headers, e.g.:
# MyApache/FixupInputHTTPHeaders.pm
package MyApache::FixupInputHTTPHeaders;
use base qw(Apache::Filter::HTTPHeadersManip);
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;
and then add to httpd.conf
<VirtualHost Zoot>
PerlInputFilterHandler +MyApache::FixupInputHTTPHeaders
</VirtualHost>
and voila, without using mod_perl HTTP callbacks you get to manipulate HTTP
(input and output) headers for any other Apache module. Chris wanted this for
his proxy module, which should work as well.
If you have comments regarding the naming or implementation/interface of this
module please let me know before I release the first version on CPAN.
BTW, this module is smart enough not to filter request/response bodies. Though
due to a bug in httpd, it can't be removed from the filters chain when its
work is done, so it passively passes the data though itself. Hopefully one day
that httpd bug will be fixed.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com