1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
package TestHooks::hookrun;
# this test runs all Apache phases from within the very first http
# phase
# XXX: may be improve the test to do a full-blown test, where each
# phase does something useful.
# see also TestProtocol::pseudo_http
use strict;
use warnings FATAL => 'all';
use Apache2::RequestRec ();
use Apache2::RequestUtil ();
use Apache2::HookRun ();
use APR::Table ();
use ModPerl::Util ();
use Apache::Test;
use Apache::TestUtil;
use Apache::TestTrace;
use Apache2::Const -compile => qw(OK DECLINED DONE SERVER_ERROR);
my $path = '/' . Apache::TestRequest::module2path(__PACKAGE__);
my @phases = qw(
PerlPostReadRequestHandler
PerlTransHandler
PerlMapToStorageHandler
PerlHeaderParserHandler
PerlAccessHandler
PerlAuthenHandler
PerlAuthzHandler
PerlTypeHandler
PerlFixupHandler
PerlResponseHandler
PerlLogHandler
);
sub post_read_request {
my $r = shift;
my $rc;
$r->push_handlers(PerlTransHandler => \&any);
$r->push_handlers(PerlMapToStorageHandler => \&any);
$r->push_handlers(PerlHeaderParserHandler => \&any);
$r->push_handlers(PerlAccessHandler => \&any);
$r->push_handlers(PerlAuthenHandler => \&any);
$r->push_handlers(PerlAuthzHandler => \&any);
$r->push_handlers(PerlTypeHandler => \&any);
$r->push_handlers(PerlFixupHandler => \&any);
$r->push_handlers(PerlLogHandler => \&any);
any($r); # indicate that the post_read_request phase was run
# for the full Apache logic for running phases starting from
# post_read_request and ending with fixup see
# ap_process_request_internal in httpd-2.0/server/request.c
$rc = $r->run_translate_name;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_map_to_storage;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
# this must be run all a big havoc will happen in the following
# phases
$r->location_merge($path);
$rc = $r->run_header_parser;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
my $args = $r->args || '';
if ($args eq 'die') {
$r->die(Apache2::Const::SERVER_ERROR);
return Apache2::Const::DONE;
}
$rc = $r->run_access_checker;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_auth_checker;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_check_user_id;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_type_checker;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_fixups;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
# $r->run_handler is called internally by $r->invoke_handler,
# invoke_handler sets all kind of filters, and does a few other
# things but it's possible to call $r->run_handler, bypassing
# invoke_handler
$rc = $r->invoke_handler;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
$rc = $r->run_log_transaction;
return $rc unless $rc == Apache2::Const::OK or $rc == Apache2::Const::DECLINED;
return Apache2::Const::DONE;
# Apache runs ap_finalize_request_protocol on return of this
# handler
}
sub any {
my $r = shift;
my $callback = ModPerl::Util::current_callback();
debug "running $callback\n";
$r->notes->set($callback => 1);
# unset the callback that was already run
$r->set_handlers($callback => []);
Apache2::Const::OK;
}
sub response {
my $r = shift;
my @pre_response = (@phases)[0..($#phases-2)];
plan tests => scalar(@pre_response);
for my $phase (@pre_response) {
my $note = $r->notes->get($phase);
$r->print("$phase:$note\n");
}
Apache2::Const::OK;
}
1;
__END__
<NoAutoConfig>
<VirtualHost TestHooks::hookrun>
PerlModule TestHooks::hookrun
PerlPostReadRequestHandler TestHooks::hookrun::post_read_request
<Location /TestHooks__hookrun>
SetHandler modperl
PerlResponseHandler TestHooks::hookrun::response
AuthName modperl
AuthType none
Require valid-user
</Location>
</VirtualHost>
</NoAutoConfig>
|