stas 2004/08/13 22:10:12
Modified: t/api .cvsignore internal_redirect.t t/response/TestAPI lookup_uri.pm . Changes todo api_status xs/maps apache_functions.map Added: t/api internal_redirect_handler.t lookup_misc.t lookup_uri.t sub_request.t t/response/TestAPI internal_redirect_handler.pm lookup_misc.pm sub_request.pm Log: - fix Apache::SubRequest's methods: lookup_file, lookup_uri, lookup_method_uri to default the last argument to r->proto_output_filters (no request filters for the subrequest) and not r->output_filters->next as it was before (one filter was getting skipped and the rest of the filters were applied *twice*). - add more sub-request tests Revision Changes Path 1.15 +0 -1 modperl-2.0/t/api/.cvsignore Index: .cvsignore =================================================================== RCS file: /home/cvs/modperl-2.0/t/api/.cvsignore,v retrieving revision 1.14 retrieving revision 1.15 diff -u -u -r1.14 -r1.15 --- .cvsignore 12 Aug 2004 06:40:45 -0000 1.14 +++ .cvsignore 14 Aug 2004 05:10:11 -0000 1.15 @@ -4,7 +4,6 @@ conn_rec.t conn_util.t lookup_uri2.t -lookup_uri.t module.t process.t query.t 1.3 +1 -1 modperl-2.0/t/api/internal_redirect.t Index: internal_redirect.t =================================================================== RCS file: /home/cvs/modperl-2.0/t/api/internal_redirect.t,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- internal_redirect.t 8 Jul 2004 05:29:42 -0000 1.2 +++ internal_redirect.t 14 Aug 2004 05:10:11 -0000 1.3 @@ -18,7 +18,7 @@ "modperl => perl-script" => "${uri}_modperl?uri=${uri}_perl_script", ); -plan tests => 4; +plan tests => scalar keys %map; while (my($key, $val) = each %map) { my $expected = "internal redirect: $key"; 1.1 modperl-2.0/t/api/internal_redirect_handler.t Index: internal_redirect_handler.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; my $uri = "/TestAPI__internal_redirect_handler"; my @ct_types = qw(text/plain text/html); plan tests => scalar @ct_types; for my $type (@ct_types) { my $expected = $type; my $received = GET_BODY_ASSERT "$uri?ct=$type"; ok t_cmp $received, $expected, "Content-type: $type"; } 1.1 modperl-2.0/t/api/lookup_misc.t Index: lookup_misc.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; use File::Spec; my $uri = "/TestAPI__lookup_misc"; my $file = File::Spec->rel2abs(__FILE__); open my $fh, $file or die "Can't open $file: $!"; my $data = do { binmode $fh; local $/; <$fh> }; close $fh; plan tests => 2; # lookup_file { my $args = "subreq=lookup_file;file=$file"; my $expected = $data; my $received = GET_BODY_ASSERT "$uri?$args"; t_debug "lookup_file"; ok $received eq $expected; } # lookup_method_uri { my $args = "subreq=lookup_method_uri;uri=/lookup_method_uri"; my $expected = "ok"; my $received = GET_BODY_ASSERT "$uri?$args"; ok t_cmp $received, $expected, "lookup_method_uri"; } 1.1 modperl-2.0/t/api/lookup_uri.t Index: lookup_uri.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; my $uri = "/TestAPI__lookup_uri"; use constant PREFIX => 0; use constant SUFFIX => 1; my %opts = ( first => [2, 2], # all filters run twice second => [1, 2], # the top level req filter skipped for the subreq none => [1, 1], # no request filters run by subreq default => [1, 1], # same as none ); plan tests => scalar keys %opts; while (my($filter, $runs) = each %opts) { my $args = "subreq=lookup_uri;filter=$filter"; my $prefix = "pre+" x $runs->[PREFIX]; my $suffix = "+suf" x $runs->[SUFFIX]; my $expected = "$prefix$args$suffix"; my $received = GET_BODY_ASSERT "$uri?$args"; ok t_cmp $received, $expected, "$args"; } 1.1 modperl-2.0/t/api/sub_request.t Index: sub_request.t =================================================================== # WARNING: this file is generated, do not edit # 01: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfig.pm:875 # 02: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfig.pm:893 # 03: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfigPerl.pm:138 # 04: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfigPerl.pm:553 # 05: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfig.pm:561 # 06: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfig.pm:576 # 07: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestConfig.pm:1505 # 08: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestRun.pm:499 # 09: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestRunPerl.pm:80 # 10: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestRun.pm:714 # 11: /home/stas/apache.org/mp2-pool/Apache-Test/lib/Apache/TestRun.pm:714 # 12: /home/stas/apache.org/mp2-pool/t/TEST:21 use Apache::TestRequest 'GET_BODY_ASSERT'; print GET_BODY_ASSERT "/TestAPI__sub_request"; 1.3 +65 -10 modperl-2.0/t/response/TestAPI/lookup_uri.pm Index: lookup_uri.pm =================================================================== RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/lookup_uri.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- lookup_uri.pm 11 Apr 2002 11:08:43 -0000 1.2 +++ lookup_uri.pm 14 Aug 2004 05:10:12 -0000 1.3 @@ -1,28 +1,83 @@ package TestAPI::lookup_uri; +# tests $r->lookup_uri and its work with filters + use strict; use warnings FATAL => 'all'; -use Apache::Test; - +use Apache::RequestRec (); +use Apache::RequestIO (); +use Apache::Filter (); use Apache::SubRequest (); use Apache::Const -compile => 'OK'; +my $uri = '/' . Apache::TestRequest::module2path(__PACKAGE__); + sub handler { my $r = shift; - my $uri = '/lookup_uri'; - my $subr = $r->lookup_uri($uri); - die unless $subr->uri eq $uri; - $subr->run; + my $args = $r->args || ''; + my %args = map { split '=', $_, 2 } split /;/, $args; + + if ($args{main}) { + $args =~ s/main=1;//; + $r->print($args); + } + else { + my $new_args = "$uri?main=1;$args"; + my $subr; + if ($args{filter} eq 'first') { + # run all request filters + $subr = $r->lookup_uri($new_args, + $r->output_filters); + } + if ($args{filter} eq 'second') { + # run all request filters, but the top one + $subr = $r->lookup_uri($new_args, + $r->output_filters->next); + } + elsif ($args{filter} eq 'default') { + # run none of request filters + $subr = $r->lookup_uri($new_args); + } + elsif ($args{filter} eq 'none') { + # run none of request filters + $subr = $r->lookup_uri($new_args, + $r->proto_output_filters); + } + else { + # nada + } + + $subr->run; + } + + Apache::OK; +} + +sub prefix_filter { + my $filter = shift; + + while ($filter->read(my $buffer, 1024)) { + $filter->print("pre+$buffer"); + } + + Apache::OK; +} + +sub suffix_filter { + my $filter = shift; + + while ($filter->read(my $buffer, 1024)) { + $filter->print("$buffer+suf"); + } Apache::OK; } 1; __DATA__ -<Location /lookup_uri> - SetHandler modperl - PerlResponseHandler Apache::TestHandler::ok1 -</Location> +PerlModule TestAPI::lookup_uri +PerlOutputFilterHandler TestAPI::lookup_uri::prefix_filter +PerlOutputFilterHandler TestAPI::lookup_uri::suffix_filter 1.1 modperl-2.0/t/response/TestAPI/internal_redirect_handler.pm Index: internal_redirect_handler.pm =================================================================== package TestAPI::internal_redirect_handler; # $r->internal_redirect_handler() is the same as # $r->internal_redirect() but it uses the same content-type as the # top-level handler use strict; use warnings FATAL => 'all'; use Apache::RequestRec (); use Apache::RequestIO (); use Apache::SubRequest (); use Apache::Const -compile => 'OK'; my $uri = '/' . Apache::TestRequest::module2path(__PACKAGE__); sub handler { my $r = shift; my %args = map { split '=', $_, 2 } split /[&]/, $r->args; if ($args{main}) { # sub-req should see the same content-type as the top-level my $ct = $r->content_type; $r->content_type('text/plain'); $r->print($ct); } else { # main-req $r->content_type($args{ct}); $r->internal_redirect_handler("$uri?main=1"); } Apache::OK; } 1; __DATA__ 1.1 modperl-2.0/t/response/TestAPI/lookup_misc.pm Index: lookup_misc.pm =================================================================== package TestAPI::lookup_misc; # testing misc lookup_ methods. TestAPI::lookup_uri includes the tests # for lookup_uri and for filters, which should be the same for all # other lookup_ methods use strict; use warnings FATAL => 'all'; use Apache::RequestRec (); use Apache::RequestIO (); use Apache::Filter (); use Apache::SubRequest (); use Apache::TestTrace; use Apache::Const -compile => 'OK'; my $uri = '/' . Apache::TestRequest::module2path(__PACKAGE__); sub handler { my $r = shift; my %args = map { split '=', $_, 2 } split /;/, $r->args; if ($args{subreq} eq 'lookup_file') { debug "lookup_file($args{file})"; my $subr = $r->lookup_file($args{file}); $subr->run; } elsif ($args{subreq} eq 'lookup_method_uri') { debug "lookup_method_uri($args{uri})"; my $subr = $r->lookup_method_uri("GET", $args{uri}); $subr->run; } else { $r->print("default"); } Apache::OK; } 1; __DATA__ <Location /lookup_method_uri> SetHandler modperl PerlResponseHandler Apache::TestHandler::ok </Location> 1.1 modperl-2.0/t/response/TestAPI/sub_request.pm Index: sub_request.pm =================================================================== package TestAPI::sub_request; # basic subrequest tests use strict; use warnings FATAL => 'all'; use Apache::RequestRec (); use Apache::RequestIO (); use Apache::SubRequest (); use Apache::Test; use Apache::TestUtil; use Apache::Const -compile => qw(OK SERVER_ERROR); my $uri = '/' . Apache::TestRequest::module2path(__PACKAGE__); sub handler { my $r = shift; my $args = $r->args || ''; return Apache::SERVER_ERROR if $args eq 'subreq'; plan $r, tests => 4; my $subr = $r->lookup_uri("$uri?subreq"); ok $subr->isa('Apache::SubRequest'); ok t_cmp $subr->uri, $uri, "uri"; my $rc = $subr->run; ok $rc, Apache::SERVER_ERROR, "rc"; # test an explictit DESTROY (which happens automatically on the # scope exit) $subr->DESTROY; ok 1; Apache::OK; } 1; __DATA__ 1.445 +6 -0 modperl-2.0/Changes Index: Changes =================================================================== RCS file: /home/cvs/modperl-2.0/Changes,v retrieving revision 1.444 retrieving revision 1.445 diff -u -u -r1.444 -r1.445 --- Changes 13 Aug 2004 04:42:37 -0000 1.444 +++ Changes 14 Aug 2004 05:10:12 -0000 1.445 @@ -12,6 +12,12 @@ =item 1.99_15-dev +fix Apache::SubRequest's methods: lookup_file, lookup_uri, +lookup_method_uri to default the last argument to +r->proto_output_filters (no request filters for the subrequest) and +not r->output_filters->next as it was before (one filter was getting +skipped and the rest of the filters were applied *twice*). [Stas] + Apache::CmdParms changes [Gozer] - readwrite => readonly: override, limited, directive, pool, temp_pool, server, path, 1.31 +3 -1 modperl-2.0/todo/api_status Index: api_status =================================================================== RCS file: /home/cvs/modperl-2.0/todo/api_status,v retrieving revision 1.30 retrieving revision 1.31 diff -u -u -r1.30 -r1.31 --- api_status 14 Aug 2004 00:24:16 -0000 1.30 +++ api_status 14 Aug 2004 05:10:12 -0000 1.31 @@ -55,7 +55,9 @@ error_log2stderr -- src/docs/2.0/api/Apache/Status.pod VV src/docs/2.0/api/Apache/SubProcess.pod --- src/docs/2.0/api/Apache/SubRequest.pod +VV src/docs/2.0/api/Apache/SubRequest.pod + internal_fast_redirect + lookup_dirent VV src/docs/2.0/api/Apache/URI.pod VV src/docs/2.0/api/Apache/Util.pod -- src/docs/2.0/api/Apache/compat.pod 1.95 +3 -3 modperl-2.0/xs/maps/apache_functions.map Index: apache_functions.map =================================================================== RCS file: /home/cvs/modperl-2.0/xs/maps/apache_functions.map,v retrieving revision 1.94 retrieving revision 1.95 diff -u -u -r1.94 -r1.95 --- apache_functions.map 11 Aug 2004 23:03:18 -0000 1.94 +++ apache_functions.map 14 Aug 2004 05:10:12 -0000 1.95 @@ -88,13 +88,13 @@ ap_sub_req_lookup_dirent | | r, finfo, subtype=AP_SUBREQ_NO_ARGS, next_filter=NULL | lookup_dirent subrequest_rec *:ap_sub_req_lookup_file | | \ - r, new_file, next_filter=r->output_filters->next | lookup_file + r, new_file, next_filter=r->proto_output_filters | lookup_file subrequest_rec *:ap_sub_req_lookup_uri | | \ - r, new_file, next_filter=r->output_filters->next | lookup_uri + r, new_file, next_filter=r->proto_output_filters | lookup_uri subrequest_rec *:ap_sub_req_method_uri | | \ - r, method, new_file, next_filter=r->output_filters->next | lookup_method_uri + r, method, new_file, next_filter=r->proto_output_filters | lookup_method_uri PACKAGE=Apache::SubRequest ISA=Apache::RequestRec ap_destroy_sub_req | | r | DESTROY