stas 2003/11/24 16:08:02
Added: t/filter both_str_req_proxy.t
t/filter/TestFilter both_str_req_proxy.pm
Log:
very similar to TestFilter::both_str_req_add, but the request is
proxified. we filter the POSTed body before it goes via the proxy and
we filter the response after it returned from the proxy
Revision Changes Path
1.1 modperl-2.0/t/filter/both_str_req_proxy.t
Index: both_str_req_proxy.t
===================================================================
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;
plan tests => 1, (have_module('proxy') && have_access);
my $data = join ' ', 'A'..'Z', 0..9;
my $expected = lc $data; # that's what the input filter does
$expected =~ s/\s+//g; # that's what the output filter does
my $location = '/TestFilter__both_str_req_proxy/foo';
my $response = POST_BODY $location, content => $data;
ok t_cmp($expected, $response, "lc input and reverse output filters");
1.1 modperl-2.0/t/filter/TestFilter/both_str_req_proxy.pm
Index: both_str_req_proxy.pm
===================================================================
package TestFilter::both_str_req_proxy;
# very similar to TestFilter::both_str_req_add, but the request is
# proxified. we filter the POSTed body before it goes via the proxy and
# we filter the response after it returned from the proxy
use strict;
use warnings FATAL => 'all';
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Filter ();
use Apache::TestTrace;
use Apache::Const -compile => qw(OK M_POST);
sub in_filter {
my $filter = shift;
debug "input filter";
while ($filter->read(my $buffer, 1024)) {
$filter->print(lc $buffer);
}
Apache::OK;
}
sub out_filter {
my $filter = shift;
debug "output filter";
while ($filter->read(my $buffer, 1024)) {
$buffer =~ s/\s+//g;
$filter->print($buffer);
}
Apache::OK;
}
sub handler {
my $r = shift;
debug "response handler";
$r->content_type('text/plain');
if ($r->method_number == Apache::M_POST) {
$r->print(ModPerl::Test::read_post($r));
}
return Apache::OK;
}
1;
__DATA__
<NoAutoConfig>
<IfModule mod_proxy.c>
<IfModule mod_access.c>
<Proxy http://@servername@:@port@/*>
Order Deny,Allow
Deny from all
Allow from @servername@
</Proxy>
ProxyRequests Off
RewriteEngine On
ProxyPass /TestFilter__both_str_req_proxy/ \
http://@servername@:@port@/TestFilter__both_str_req_proxy_content/
ProxyPassReverse /TestFilter__both_str_req_proxy/ \
http://@servername@:@port@/TestFilter__both_str_req_proxy_content/
</IfModule>
</IfModule>
PerlModule TestFilter::both_str_req_proxy
<Location /TestFilter__both_str_req_proxy>
PerlInputFilterHandler TestFilter::both_str_req_proxy::in_filter
PerlOutputFilterHandler TestFilter::both_str_req_proxy::out_filter
</Location>
<Location /TestFilter__both_str_req_proxy_content>
SetHandler modperl
PerlResponseHandler TestFilter::both_str_req_proxy
</Location>
</NoAutoConfig>