Plack handler apache2 improvements #341

wants to merge 2 commits into
Commits on Oct 16, 2012
  1. @avar

    Plack::Handler::Apache2: add a new plack.handler.apache.request.objec…

    avar committed Oct 16, 2012
    …t key
    Add a plack.handler.apache.request.object key which contains the
    Apache request object, this allows the application to access the
    original Apache request object. Originally I had used psgi.input for
    this, but in some cases it's going to be overwritten to e.g.:
        bless( \*{'Plack::TempBuffer::PerlIO::$io'}, 'FileHandle' )
    I think something like Plack::Request might be overwriting it, but in
    any case we need a new key to access this since other things are going
    to munge it.
    This patch only adds a new key and doesn't change any existing ones,
    it's best viewed with "git show -w".
  2. @avar

    Plack::Handler::Apache2: preserve a copy of %ENV for cleanup handlers

    avar committed Oct 16, 2012
    For reasons unknown we'll *sometimes* have an emptied out %ENV by the
    time we run the cleanup phase, I can reproduce this by requesting any
    URL in my application a few times.
    With this patch applied to Plack::Handler::Apache2:
        @@ -90,9 +92,12 @@ sub call_app {
                 die "Bad response $res";
        +    print STDERR "Have done everything, have the env = " . Data::Dumper::Dumper(\%ENV);
             if (@{ $env->{'psgix.cleanup.handlers'} }) {
                     PerlCleanupHandler => sub {
        +                print STDERR "Running the cleanup handler, have the env = " . Data::Dumper::Dumper(\%ENV);
                         for my $cleanup_handler (@{ $env->{'psgix.cleanup.handlers'} }) {
    I'll always get the full %ENV when I dump it in "Have done
    everything", but by the time I get to running the cleanup handlers
    it's sometimes been completely emptied.
    Work around this by preserving %ENV and restoring it if it gets lost,
    this helps a lot with migrating existing Apache applications which
    look at %ENV, and since we normally set %ENV with the "subprocess_env"
    cal it's really confusing to only provide it some of the time.