Fixed FastCGI engine to not clobber the global %ENV on each request (Sam Vilain)
Andy Grundman [Tue, 15 Nov 2005 14:50:04 +0000 (14:50 +0000)]
Changes
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Engine/FastCGI.pm

diff --git a/Changes b/Changes
index ff8f7e1..6721e00 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 This file documents the revision history for Perl extension Catalyst.
 
+5.56
+        - Fixed FastCGI engine to not clobber the global %ENV on each
+          request. (Sam Vilain)
+
 5.55    2005-11-15 12:55:00
         - Fixed multiple cookie handling
 
index 950cc2d..741816e 100644 (file)
@@ -5,6 +5,8 @@ use base 'Catalyst::Engine';
 use NEXT;
 use URI;
 
+__PACKAGE__->mk_accessors( 'env' );
+
 =head1 NAME
 
 Catalyst::Engine::CGI - The CGI Engine
@@ -53,6 +55,7 @@ sub finalize_headers {
 
 sub prepare_connection {
     my ( $self, $c ) = @_;
+    local(*ENV) = $self->env || \%ENV;
 
     $c->request->address( $ENV{REMOTE_ADDR} );
 
@@ -90,6 +93,7 @@ sub prepare_connection {
 
 sub prepare_headers {
     my ( $self, $c ) = @_;
+    local(*ENV) = $self->env || \%ENV;
 
     # Read headers from %ENV
     while ( my ( $header, $value ) = each %ENV ) {
@@ -105,6 +109,7 @@ sub prepare_headers {
 
 sub prepare_path {
     my ( $self, $c ) = @_;
+    local(*ENV) = $self->env || \%ENV;
 
     my $scheme = $c->request->secure ? 'https' : 'http';
     my $host      = $ENV{HTTP_HOST}   || $ENV{SERVER_NAME};
@@ -155,12 +160,25 @@ sub prepare_path {
 
 sub prepare_query_parameters {
     my ( $self, $c ) = @_;
+    local(*ENV) = $self->env || \%ENV;
     
     if ( $ENV{QUERY_STRING} ) {
         $self->SUPER::prepare_query_parameters( $c, $ENV{QUERY_STRING} );
     }
 }
 
+=item $self->prepare_request($c, (env => \%env))
+
+=cut
+
+sub prepare_request {
+    my ( $self, $c, %args ) = @_;
+
+    if ( $args{env} ) {
+       $self->env( $args{env} );
+    }
+}
+
 =item $self->prepare_write($c)
 
 Enable autoflush on the output handle for CGI-based engines.
index d832bea..4ff269e 100644 (file)
@@ -61,9 +61,11 @@ sub run {
     }
 
     $options ||= {};
+    
+    my %env;
 
     my $request =
-      FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%ENV, $sock,
+      FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%env, $sock,
         ( $options->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR ),
       );
 
@@ -78,7 +80,7 @@ sub run {
 
     while ( $request->Accept >= 0 ) {
         $proc_manager && $proc_manager->pm_pre_dispatch();
-        $class->handle_request;
+        $class->handle_request( env => \%env );
         $proc_manager && $proc_manager->pm_pre_dispatch();
     }
 }