gitweb: Run in FastCGI mode if gitweb script has .fcgi extension
authorJakub Narebski <jnareb@gmail.com>
Sat, 5 Jun 2010 21:11:18 +0000 (23:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Jun 2010 15:54:35 +0000 (08:54 -0700)
If the name of the script ($SCRIPT_NAME or $SCRIPT_FILENAME CGI
environment variable, or __FILE__ literal) ends with '.fcgi'
extension, run gitweb in FastCGI mode, as if it was run with
'--fastcgi' / '--fcgi' option.

This is intended for easy deploying gitweb using FastCGI
interface.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb/gitweb.perl
index b044d18acaff0527a4da9a37f8587be955eb4f0f..e39ef866f02d07487d36f9198be8bad5c8aeeabc 100755 (executable)
@@ -1025,19 +1025,24 @@ sub run_request {
 our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
 our $CGI = 'CGI';
 our $cgi;
+sub configure_as_fcgi {
+       require CGI::Fast;
+       our $CGI = 'CGI::Fast';
+
+       my $request_number = 0;
+       # let each child service 100 requests
+       our $is_last_request = sub { ++$request_number > 100 };
+}
 sub evaluate_argv {
+       my $script_name = $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || __FILE__;
+       configure_as_fcgi()
+               if $script_name =~ /\.fcgi$/;
+
        return unless (@ARGV);
 
        require Getopt::Long;
        Getopt::Long::GetOptions(
-               'fastcgi|fcgi|f' => sub {
-                       require CGI::Fast;
-                       our $CGI = 'CGI::Fast';
-
-                       my $request_number = 0;
-                       # let each child service 100 requests
-                       our $is_last_request = sub { ++$request_number > 100 };
-               },
+               'fastcgi|fcgi|f' => \&configure_as_fcgi,
                'nproc|n=i' => sub {
                        my ($arg, $val) = @_;
                        return unless eval { require FCGI::ProcManager; 1; };