Changeset 668

Show
Ignore:
Timestamp:
08/22/06 16:43:51 (2 years ago)
Author:
bchoate
Message:

Added FastCGI support to Bootstrap itself, so cgi scripts can run as FastCGI apps without modification.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/wheeljack/lib/MT/Bootstrap.pm

    r2 r668  
    22 
    33use strict; 
    4 use MT; 
    54 
    65sub BEGIN { 
     
    3736 
    3837    if ($class) { 
     38        # When running under FastCGI, the initial invocation of the 
     39        # script has a bare environment. We can use this to test 
     40        # for FastCGI. 
     41        my $not_fast_cgi = 0; 
     42        $not_fast_cgi ||= exists $ENV{$_} 
     43            for qw(HTTP_HOST GATEWAY_INTERFACE SCRIPT_FILENAME SCRIPT_URL); 
     44        my $fast_cgi = (!$not_fast_cgi) || $param{FastCGI}; 
     45        require CGI::Fast if $fast_cgi; 
     46 
    3947        # ready to run now... run inside an eval block so we can gracefully 
    4048        # die if something bad happens 
    4149        my $app; 
    4250        eval { 
     51            require MT; 
    4352            eval "require $class; 1;" or die $@; 
    44             $app = $class->new( %param ) or die $class->errstr; 
    45             local $SIG{__WARN__} = sub { $app->trace($_[0]) }; 
    46             MT->set_instance($app); 
    47             $app->run; 
     53            if ($fast_cgi) { 
     54                while (my $cgi = new CGI::Fast) { 
     55                    $app = $class->new( %param ) or die $class->errstr; 
     56                    local $SIG{__WARN__} = sub { $app->trace($_[0]) }; 
     57                    MT->set_instance($app); 
     58                    $app->init_request(CGIObject => $cgi) 
     59                        unless $app->{init_request}; 
     60                    $app->run; 
     61                } 
     62            } else { 
     63                $app = $class->new( %param ) or die $class->errstr; 
     64                local $SIG{__WARN__} = sub { $app->trace($_[0]) }; 
     65                $app->run; 
     66            } 
    4867        }; 
    4968        if (my $err = $@) {