stas 2004/05/12 18:59:18
Modified: t/filter in_str_msg.t t/filter/TestFilter in_str_msg.pm Log: in addition to what was already tested, test: - input request filter configured outside the resource container should work just fine (via PerlOptions +MergeHandlers) - input connection filter configured inside the resource container is silently skipped (at the moment we can't complain about such, since there could be connection filters from outside the resource container that will get merged inside the resource dir_config Revision Changes Path 1.4 +2 -2 modperl-2.0/t/filter/in_str_msg.t Index: in_str_msg.t =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/in_str_msg.t,v retrieving revision 1.3 retrieving revision 1.4 diff -u -u -r1.3 -r1.4 --- in_str_msg.t 11 May 2003 22:59:21 -0000 1.3 +++ in_str_msg.t 13 May 2004 01:59:18 -0000 1.4 @@ -1,7 +1,7 @@ use Apache::Test (); use Apache::TestUtil; -use Apache::TestRequest 'GET_BODY_ASSERT'; +use Apache::TestRequest 'POST_BODY_ASSERT'; my $module = 'TestFilter::in_str_msg'; @@ -12,4 +12,4 @@ my $hostport = Apache::TestRequest::hostport($config); t_debug("connecting to $hostport"); -print GET_BODY_ASSERT "/input_filter.html"; +print POST_BODY_ASSERT "/input_filter.html", content => "upcase me"; 1.6 +53 -6 modperl-2.0/t/filter/TestFilter/in_str_msg.pm Index: in_str_msg.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/in_str_msg.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -u -r1.5 -r1.6 --- in_str_msg.pm 9 Feb 2004 18:18:16 -0000 1.5 +++ in_str_msg.pm 13 May 2004 01:59:18 -0000 1.6 @@ -1,5 +1,14 @@ package TestFilter::in_str_msg; +# test: +# - input connection filter rewriting the first HTTP header POST +# - input request filter configured outside the resource container +# should work just fine (via PerlOptions +MergeHandlers) +# - input connection filter configured inside the resource container +# is silently skipped (at the moment we can't complain about such, +# since there could be connection filters from outside the resource +# container that will get merged inside the resource dir_config + use strict; use warnings FATAL => 'all'; @@ -10,22 +19,25 @@ use APR::Brigade (); use APR::Bucket (); +use Apache::Test; +use Apache::TestUtil; + use Apache::Const -compile => 'OK'; use APR::Const -compile => ':common'; my $from_url = '/input_filter.html'; my $to_url = '/TestFilter__in_str_msg'; -sub handler : FilterConnectionHandler { +sub con : FilterConnectionHandler { my $filter = shift; - #warn "FILTER CALLED\n"; + #warn "FILTER con CALLED\n"; my $ctx = $filter->ctx; while ($filter->read(my $buffer, 1024)) { #warn "FILTER READ: $buffer\n"; unless ($ctx) { - $buffer =~ s|GET $from_url|GET $to_url|; + $buffer =~ s|POST $from_url|POST $to_url|; $ctx = 1; # done } $filter->print($buffer); @@ -35,25 +47,60 @@ return Apache::OK; } +sub req : FilterRequestHandler { + my $filter = shift; + + #warn "FILTER req CALLED\n"; + while ($filter->read(my $buffer, 1024)) { + $buffer =~ s/upcase me/UPCASED/; + $filter->print($buffer); + } + + return Apache::OK; +} + +sub con_skip : FilterConnectionHandler { + my $filter = shift; + + #warn "FILTER con_skip CALLED\n"; + while ($filter->read(my $buffer, 1024)) { + $filter->print("I'm a bogus filter. Don't run me\n"); + } + + return Apache::OK; +} + +my $expected = "UPCASED"; sub response { my $r = shift; - $r->content_type('text/plain'); + plan $r, tests => 1; - $r->puts("1..1\nok 1\n"); + my $received = ModPerl::Test::read_post($r); + + ok t_cmp($expected, $received, + "request filter must have upcased the data"); Apache::OK; } 1; __END__ +<NoAutoConfig> <VirtualHost TestFilter::in_str_msg> PerlModule TestFilter::in_str_msg - PerlInputFilterHandler TestFilter::in_str_msg + PerlInputFilterHandler TestFilter::in_str_msg::con + + # this request filter is outside the resource container and it + # should work just fine because of PerlOptions +MergeHandlers + PerlInputFilterHandler TestFilter::in_str_msg::req <Location /TestFilter__in_str_msg> SetHandler modperl + PerlOptions +MergeHandlers + PerlInputFilterHandler TestFilter::in_str_msg::con_skip PerlResponseHandler TestFilter::in_str_msg::response </Location> </VirtualHost> +</NoAutoConfig>