Skip to content

Commit

Permalink
Merge pull request #334 from avar/add-support-for-psgix_cleanup-to-ap…
Browse files Browse the repository at this point in the history
…ache2-handler

Plack::Handler::Apache2: implement support for cleanup handlers
  • Loading branch information
miyagawa committed Sep 30, 2012
2 parents b8eadec + 598c18c commit c8d0ffc
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions lib/Plack/Handler/Apache2.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ sub call_app {


my $env = { my $env = {
%ENV, %ENV,
'psgi.version' => [ 1, 1 ], 'psgi.version' => [ 1, 1 ],
'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http', 'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
'psgi.input' => $r, 'psgi.input' => $r,
'psgi.errors' => *STDERR, 'psgi.errors' => *STDERR,
'psgi.multithread' => Plack::Util::FALSE, 'psgi.multithread' => Plack::Util::FALSE,
'psgi.multiprocess' => Plack::Util::TRUE, 'psgi.multiprocess' => Plack::Util::TRUE,
'psgi.run_once' => Plack::Util::FALSE, 'psgi.run_once' => Plack::Util::FALSE,
'psgi.streaming' => Plack::Util::TRUE, 'psgi.streaming' => Plack::Util::TRUE,
'psgi.nonblocking' => Plack::Util::FALSE, 'psgi.nonblocking' => Plack::Util::FALSE,
'psgix.harakiri' => Plack::Util::TRUE, 'psgix.harakiri' => Plack::Util::TRUE,
'psgix.cleanup' => Plack::Util::TRUE,
'psgix.cleanup.handlers' => [],
}; };


if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) { if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
Expand Down Expand Up @@ -87,8 +89,22 @@ sub call_app {
die "Bad response $res"; die "Bad response $res";
} }


if ($env->{'psgix.harakiri.commit'}) { if (@{ $env->{'psgix.cleanup.handlers'} }) {
$r->child_terminate; $r->push_handlers(
PerlCleanupHandler => sub {
for my $cleanup_handler (@{ $env->{'psgix.cleanup.handlers'} }) {
$cleanup_handler->($env);
}

if ($env->{'psgix.harakiri.commit'}) {
$r->child_terminate;
}
},
);
} else {
if ($env->{'psgix.harakiri.commit'}) {
$r->child_terminate;
}
} }


return Apache2::Const::OK; return Apache2::Const::OK;
Expand Down

0 comments on commit c8d0ffc

Please sign in to comment.