Skip to content
Browse files

Merge pull request #334 from avar/add-support-for-psgix_cleanup-to-ap…

…ache2-handler

Plack::Handler::Apache2: implement support for cleanup handlers
  • Loading branch information...
2 parents b8eadec + 598c18c commit c8d0ffc2e8e9691e4f298f4476437d132a7af455 @miyagawa miyagawa committed Sep 29, 2012
Showing with 28 additions and 12 deletions.
  1. +28 −12 lib/Plack/Handler/Apache2.pm
View
40 lib/Plack/Handler/Apache2.pm
@@ -50,16 +50,18 @@ sub call_app {
my $env = {
%ENV,
- 'psgi.version' => [ 1, 1 ],
- 'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
- 'psgi.input' => $r,
- 'psgi.errors' => *STDERR,
- 'psgi.multithread' => Plack::Util::FALSE,
- 'psgi.multiprocess' => Plack::Util::TRUE,
- 'psgi.run_once' => Plack::Util::FALSE,
- 'psgi.streaming' => Plack::Util::TRUE,
- 'psgi.nonblocking' => Plack::Util::FALSE,
- 'psgix.harakiri' => Plack::Util::TRUE,
+ 'psgi.version' => [ 1, 1 ],
+ 'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
+ 'psgi.input' => $r,
+ 'psgi.errors' => *STDERR,
+ 'psgi.multithread' => Plack::Util::FALSE,
+ 'psgi.multiprocess' => Plack::Util::TRUE,
+ 'psgi.run_once' => Plack::Util::FALSE,
+ 'psgi.streaming' => Plack::Util::TRUE,
+ 'psgi.nonblocking' => Plack::Util::FALSE,
+ 'psgix.harakiri' => Plack::Util::TRUE,
+ 'psgix.cleanup' => Plack::Util::TRUE,
+ 'psgix.cleanup.handlers' => [],
};
if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
@@ -87,8 +89,22 @@ sub call_app {
die "Bad response $res";
}
- if ($env->{'psgix.harakiri.commit'}) {
- $r->child_terminate;
+ if (@{ $env->{'psgix.cleanup.handlers'} }) {
+ $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;

0 comments on commit c8d0ffc

Please sign in to comment.
Something went wrong with that request. Please try again.