summaryrefslogtreecommitdiffstats
path: root/config.cgi
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-11-09 20:04:50 +0100
committermkanat%bugzilla.org <>2009-11-09 20:04:50 +0100
commit6188fad092e9f347a111ed30d0e21bb048d69998 (patch)
tree93de55a79ba8e61ec620ab9a641c7103fc32655a /config.cgi
parent36d69066d3e7d72620dc94279841aba945da6ce7 (diff)
downloadbugzilla-6188fad092e9f347a111ed30d0e21bb048d69998.tar.gz
bugzilla-6188fad092e9f347a111ed30d0e21bb048d69998.tar.xz
Bug 515644: Provide ETag support for config.cgi
Patch by Frank Becker <Frank@Frank-Becker.de> r=mkanat, a=mkanat
Diffstat (limited to 'config.cgi')
-rwxr-xr-xconfig.cgi42
1 files changed, 37 insertions, 5 deletions
diff --git a/config.cgi b/config.cgi
index 282b95957..2d8c2d92c 100755
--- a/config.cgi
+++ b/config.cgi
@@ -20,6 +20,7 @@
#
# Contributor(s): Terry Weissman <terry@mozilla.org>
# Myk Melez <myk@mozilla.org>
+# Frank Becker <Frank@Frank-Becker.de>
################################################################################
# Script Initialization
@@ -36,6 +37,7 @@ use Bugzilla::Error;
use Bugzilla::Keyword;
use Bugzilla::Status;
use Bugzilla::Field;
+use Digest::MD5 qw(md5_base64);
my $user = Bugzilla->login(LOGIN_OPTIONAL);
my $cgi = Bugzilla->cgi;
@@ -110,11 +112,41 @@ sub display_data {
my $format = $template->get_format("config", scalar($cgi->param('format')),
scalar($cgi->param('ctype')) || "js");
- # Return HTTP headers.
- print "Content-Type: $format->{'ctype'}\n\n";
-
- # Generate the configuration file and return it to the user.
- $template->process($format->{'template'}, $vars)
+ # Generate the configuration data.
+ my $output;
+ $template->process($format->{'template'}, $vars, \$output)
|| ThrowTemplateError($template->error());
+
+ # Wide characters cause md5_base64() to die.
+ my $digest_data = $output;
+ utf8::encode($digest_data) if utf8::is_utf8($digest_data);
+ my $digest = md5_base64($digest_data);
+
+ # ETag support.
+ my $if_none_match = $cgi->http('If-None-Match') || "";
+ my $found304;
+ my @if_none = split(/[\s,]+/, $if_none_match);
+ foreach my $if_none (@if_none) {
+ # remove quotes from begin and end of the string
+ $if_none =~ s/^\"//g;
+ $if_none =~ s/\"$//g;
+ if ($if_none eq $digest or $if_none eq '*') {
+ # leave the loop after the first match
+ $found304 = $if_none;
+ last;
+ }
+ }
+
+ if ($found304) {
+ print $cgi->header(-type => 'text/html',
+ -ETag => $found304,
+ -status => '304 Not Modified');
+ }
+ else {
+ # Return HTTP headers.
+ print $cgi->header (-ETag => $digest,
+ -type => $format->{'ctype'});
+ print $output;
+ }
exit;
}