]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1520202 - Sometimes the browser can cache the wrong version of an asset
authorDylan William Hardison <dylan@hardison.net>
Tue, 22 Jan 2019 16:58:54 +0000 (11:58 -0500)
committerGitHub <noreply@github.com>
Tue, 22 Jan 2019 16:58:54 +0000 (11:58 -0500)
Bugzilla/App.pm
Bugzilla/App/Static.pm

index b8c6e6ae5e78dd608667d8f62212788827e88a89..be6d275b2afb45c3b624dae4ae71c4567cf7642b 100644 (file)
@@ -51,7 +51,7 @@ sub startup {
   $self->plugin('Bugzilla::App::Plugin::Helpers');
   $self->plugin('Bugzilla::App::Plugin::OAuth2');
 
-  push @{ $self->commands->namespaces }, 'Bugzilla::App::Command';
+  push @{$self->commands->namespaces}, 'Bugzilla::App::Command';
 
   $self->sessions->cookie_name('bugzilla');
 
@@ -115,7 +115,13 @@ sub startup {
     $self->hook(
       after_static => sub {
         my ($c) = @_;
-        $c->res->headers->cache_control('public, max-age=31536000, immutable');
+        my $version = $c->stash->{static_file_version};
+        if ($version && $version > Bugzilla->VERSION) {
+          $c->res->headers->cache_control('no-cache, no-store');
+        }
+        else {
+          $c->res->headers->cache_control('public, max-age=31536000, immutable');
+        }
       }
     );
   }
index ada937273acb83bc63609e563ab6fd099251f4df..ea36cf480a102165f4383225ce81d8bbf7a78b82 100644 (file)
@@ -10,20 +10,23 @@ use Mojo::Base 'Mojolicious::Static';
 use Bugzilla::Constants qw(bz_locations);
 
 my $LEGACY_RE = qr{
-    ^ (?:static/v[0-9]+\.[0-9]+/) ?
-    ( (?:extensions/[^/]+/web|(?:image|skin|j|graph)s)/.+)
+    ^ (?:static/v(?<version>[0-9]+\.[0-9]+)/) ?
+    (?<file>(?:extensions/[^/]+/web|(?:image|skin|j|graph)s)/.+)
     $
 }xs;
 
-sub file {
-  my ($self, $rel) = @_;
+sub serve {
+  my ($self, $c, $rel) = @_;
 
-  if (my ($legacy_rel) = $rel =~ $LEGACY_RE) {
+  if ($rel =~ $LEGACY_RE) {
     local $self->{paths} = [bz_locations->{cgi_path}];
-    return $self->SUPER::file($legacy_rel);
+    my $version = $+{version};
+    my $file    = $+{file};
+    $c->stash->{static_file_version} = $version;
+    return $self->SUPER::serve($c, $file);
   }
   else {
-    return $self->SUPER::file($rel);
+    return $self->SUPER::serve($c, $rel);
   }
 }