summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2017-03-30 16:52:49 +0200
committerDylan William Hardison <dylan@hardison.net>2017-03-30 16:52:49 +0200
commit30c35b3aefc582e1bb123b309f9c4971c04094ee (patch)
tree32f82fc5900037064fce064100692b8b0459f24c
parentb2744a52da0672ae2883b808fb88c15faf50c26b (diff)
downloadbugzilla-30c35b3aefc582e1bb123b309f9c4971c04094ee.tar.gz
bugzilla-30c35b3aefc582e1bb123b309f9c4971c04094ee.tar.xz
Bug 1351695 - Allow apache to ignore .htaccess for increased performance
-rw-r--r--Bugzilla/ModPerl.pm86
-rw-r--r--mod_perl.pl24
2 files changed, 90 insertions, 20 deletions
diff --git a/Bugzilla/ModPerl.pm b/Bugzilla/ModPerl.pm
new file mode 100644
index 000000000..22be8e678
--- /dev/null
+++ b/Bugzilla/ModPerl.pm
@@ -0,0 +1,86 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::ModPerl;
+
+use 5.10.1;
+use strict;
+use warnings;
+
+use File::Find ();
+use Cwd ();
+use Carp ();
+
+# We don't need (or want) to use Bugzilla's template subclass.
+# it is easier to reason with the code without all the extra things Bugzilla::Template adds
+# (and there might be side-effects, since this code is loaded very early in the httpd startup)
+use Template ();
+
+sub apache_config {
+ my ($class, $cgi_path) = @_;
+
+ Carp::croak "\$cgi_path is required" unless $cgi_path;
+
+ my %htaccess;
+ $cgi_path = Cwd::realpath($cgi_path);
+ my $wanted = sub {
+ package File::Find;
+ our ($name, $dir);
+
+ if ($name =~ m#/\.htaccess$#) {
+ open my $fh, '<', $name or die "cannot open $name $!";
+ my $contents = do {
+ local $/ = undef;
+ <$fh>;
+ };
+ close $fh;
+ $htaccess{$dir} = { file => $name, contents => $contents, dir => $dir };
+ }
+ };
+
+ File::Find::find( { wanted => $wanted, no_chdir => 1 }, $cgi_path );
+ my $template = Template->new;
+ my $conf;
+ my %vars = (
+ root_htaccess => delete $htaccess{$cgi_path},
+ htaccess_files => [ map { $htaccess{$_} } sort { length $a <=> length $b } keys %htaccess ],
+ cgi_path => $cgi_path,
+ );
+ $template->process(\*DATA, \%vars, \$conf);
+
+ return $conf;
+}
+
+1;
+
+__DATA__
+# Make sure each httpd child receives a different random seed (bug 476622).
+# Bugzilla::RNG has one srand that needs to be called for
+# every process, and Perl has another. (Various Perl modules still use
+# the built-in rand(), even though we never use it in Bugzilla itself,
+# so we need to srand() both of them.)
+PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); }"
+
+<Directory "[% cgi_path %]">
+ AddHandler perl-script .cgi
+ # No need to PerlModule these because they're already defined in mod_perl.pl
+ PerlResponseHandler Bugzilla::ModPerl::ResponseHandler
+ PerlCleanupHandler Bugzilla::ModPerl::CleanupHandler Apache2::SizeLimit
+ PerlOptions +ParseHeaders
+ Options +ExecCGI +FollowSymLinks
+ DirectoryIndex index.cgi index.html
+ AllowOverride none
+ # from [% root_htaccess.file %]
+ [% root_htaccess.contents FILTER indent %]
+</Directory>
+
+# directory rules for all the other places we have .htaccess files
+[% FOREACH htaccess IN htaccess_files %]
+# from [% htaccess.file %]
+<Directory "[% htaccess.dir %]">
+ [% htaccess.contents FILTER indent %]
+</Directory>
+[% END %]
diff --git a/mod_perl.pl b/mod_perl.pl
index 920032fe7..0a0a0df6a 100644
--- a/mod_perl.pl
+++ b/mod_perl.pl
@@ -38,6 +38,7 @@ use Apache2::ServerUtil;
use Apache2::SizeLimit;
use ModPerl::RegistryLoader ();
use File::Basename ();
+use File::Find ();
# This loads most of our modules.
use Bugzilla ();
@@ -48,6 +49,7 @@ use Bugzilla::Extension ();
use Bugzilla::Install::Requirements ();
use Bugzilla::Util ();
use Bugzilla::RNG ();
+use Bugzilla::ModPerl ();
# Make warnings go to the virtual host's log and not the main
# server log.
@@ -69,26 +71,8 @@ my $cgi_path = Bugzilla::Constants::bz_locations()->{'cgi_path'};
# Set up the configuration for the web server
my $server = Apache2::ServerUtil->server;
-my $conf = <<EOT;
-# Make sure each httpd child receives a different random seed (bug 476622).
-# Bugzilla::RNG has one srand that needs to be called for
-# every process, and Perl has another. (Various Perl modules still use
-# the built-in rand(), even though we never use it in Bugzilla itself,
-# so we need to srand() both of them.)
-PerlChildInitHandler "sub { Bugzilla::RNG::srand(); srand(); }"
-<Directory "$cgi_path">
- AddHandler perl-script .cgi
- # No need to PerlModule these because they're already defined in mod_perl.pl
- PerlResponseHandler Bugzilla::ModPerl::ResponseHandler
- PerlCleanupHandler Bugzilla::ModPerl::CleanupHandler Apache2::SizeLimit
- PerlOptions +ParseHeaders
- Options +ExecCGI +FollowSymLinks
- AllowOverride Limit FileInfo Indexes
- DirectoryIndex index.cgi index.html
-</Directory>
-EOT
-
-$server->add_config([split("\n", $conf)]);
+my $conf = Bugzilla::ModPerl->apache_config($cgi_path);
+$server->add_config([ grep { length $_ } split("\n", $conf)]);
# Pre-load all extensions
$Bugzilla::extension_packages = Bugzilla::Extension->load_all();