git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 5/6] gitweb: Make possible to run under mod_perl without SetupEnv

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 27, 2006, 23:49 UTC
Message-ID
<200612280049.13385.jnareb@gmail.com>
In-Reply-To
<200612272355.31923.jnareb@gmail.com>

Make possible to run gitweb under mod_perl without need to set up CGI environmental variables (i.e. "PerlOptions -SetupEnv" in mod_perl 2.0, "PerlSetupEnv Off" in mod_perl 1.0).

Actually ModPerl::Registry / Apache::Registry populates %ENV hash, without need to actually set environmental variables.

Pass the request variable $r to CGI constructor if CGI.pm module is new enough (at least CGI version 2.93, and at least 3.11 for mod_perl 2.0).

Replace $ENV{'PATH_INFO'} by $r->path_info() if we use mod_perl.

Replace $ENV{'SERVER_NAME'} by $r->server()->server_hostname() if we use mod_perl.

Uniquify using of %ENV to $ENV{'NAME'}, while at it.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch appears to be unnecessary, at least for now, because
mod_perl Registry populates %ENV hash (and does not need to set
envirionmental variables). Still, it prepares the way for future
running gitweb as mod_perl handler, and not under Registry.

Perhaps the cleanup part of this patch should be put into separate patch...

 gitweb/gitweb.perl |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 9983e9e..2900ae6 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -32,11 +32,16 @@ BEGIN {
 	# use appropriate mod_perl modules (conditional use)
 	if (MP_GEN == 2) {
 		require Apache2::RequestRec;
+		require Apache2::ServerRec;
+		require Apache2::Response;
 		require Apache2::Const;
+		Apache2::RequestRec->import();
+		Apache2::ServerRec->import();
 		Apache2::Const->import(-compile => qw(:common :http));
 	} elsif (MP_GEN == 1) {
 		require Apache;
 		require Apache::Constants;
+		import Apache;
 		Apache::Constants->import(qw(:common :http));
 	}
 
@@ -48,7 +53,15 @@ BEGIN {
 my $r;
 $r = shift @_ if MP_GEN;
 
-our $cgi = new CGI;
+our $cgi;
+if ((MP_GEN == 1 && $CGI::VERSION >= 2.93) ||
+    (MP_GEN == 2 && $CGI::VERSION >= 3.11)) {
+	# CGI.pm is new enough
+	$cgi = new CGI($r);
+} else {
+	$cgi = new CGI;
+}
+
 our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
 our $my_uri = $cgi->url(-absolute => 1);
@@ -70,7 +83,8 @@ our $home_link_str = "++GITWEB_HOME_LINK_STR++";
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
 our $site_name = "++GITWEB_SITENAME++"
-                 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
+                 || (($r ? $r->server()->server_hostname() : $ENV{'SERVER_NAME'})
+                     || "Untitled") . " Git";
 
 # filename of html text to include at top of each page
 our $site_header = "++GITWEB_SITE_HEADER++";
@@ -403,7 +417,7 @@ if (defined $searchtype) {
 # now read PATH_INFO and use it as alternative to parameters
 sub evaluate_path_info {
 	return if defined $project;
-	my $path_info = $ENV{"PATH_INFO"};
+	my $path_info = $r ? $r->path_info() : $ENV{'PATH_INFO'};
 	return if !$path_info;
 	$path_info =~ s,^/+,,;
 	return if !$path_info;
-- 
1.4.4.3
Previous: Jakub NarebskiNext: Jakub Narebski
Message 8 of 11 in “gitweb: Some mod_perl specific support (but not only)”
  1. 0/6 gitweb: Some mod_perl specific support (but not only)Jakub Narebski, Dec 27, 2006
  2. 1/6 gitweb: Separate HTTP header outputJakub Narebski, Dec 27, 2006
  3. Junio C HamanoDec 28, 2006
  4. Shawn PearceDec 28, 2006
  5. 2/6 gitweb: Add mod_perl version string to "generator" meta headerJakub Narebski, Dec 27, 2006
  6. 3/6 gitweb: Precompile CGI routines for mod_perlJakub Narebski, Dec 27, 2006
  7. 4/6 gitweb: Prepare for mod_perl specific supportJakub Narebski, Dec 27, 2006
  8. 5/6 gitweb: Make possible to run under mod_perl without SetupEnvJakub Narebski, Dec 27, 2006
  9. 6/6 gitweb: Make possible to run under mod_perl without ParseHeadersJakub Narebski, Dec 28, 2006
  10. Robert FitzsimonsDec 28, 2006
  11. Jakub NarebskiDec 28, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.