[Rt-commit] rt branch, 4.2/cache-control-regression, created. rt-4.2.3-60-gdf81b84
Wallace Reis
wreis at bestpractical.com
Wed Mar 26 14:13:43 EDT 2014
The branch, 4.2/cache-control-regression has been created
at df81b84b875e13ba86802bca52428be40889fdbb (commit)
- Log -----------------------------------------------------------------
commit df81b84b875e13ba86802bca52428be40889fdbb
Author: Wallace Reis <wreis at bestpractical.com>
Date: Wed Mar 26 13:54:24 2014 -0300
I#28640: Set headers for static content
This is a regression fix since at some point the static content served
from /static/ path had the 'Expires' and 'Cache-Control' headers removed
(probably when started serving it from Static middleware). Additionally,
add support for static content served from custom StaticRoots.
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index 078091f..e518bff 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -331,6 +331,10 @@ sub StaticWrap {
for my $static ( RT->Config->Get('StaticRoots') ) {
if ( ref $static && ref $static eq 'HASH' ) {
$builder->add_middleware(
+ '+RT::Interface::Web::Middleware::StaticHeaders',
+ path => $static->{'path'},
+ );
+ $builder->add_middleware(
'Plack::Middleware::Static',
pass_through => 1,
%$static
@@ -342,10 +346,15 @@ sub StaticWrap {
}
}
+ my $path = sub { s!^/static/!! };
+ $builder->add_middleware(
+ '+RT::Interface::Web::Middleware::StaticHeaders',
+ path => $path,
+ );
for my $root (RT::Interface::Web->StaticRoots) {
$builder->add_middleware(
'Plack::Middleware::Static',
- path => sub { s!^/static/!! },
+ path => $path,
root => $root,
pass_through => 1,
);
diff --git a/lib/RT/Interface/Web/Middleware/StaticHeaders.pm b/lib/RT/Interface/Web/Middleware/StaticHeaders.pm
new file mode 100644
index 0000000..a3a9646
--- /dev/null
+++ b/lib/RT/Interface/Web/Middleware/StaticHeaders.pm
@@ -0,0 +1,39 @@
+package RT::Interface::Web::Middleware::StaticHeaders;
+
+use strict;
+use warnings;
+use base 'Plack::Middleware';
+use Plack::Util;
+
+use Plack::Util::Accessor qw(path);
+
+sub call {
+ my ( $self, $env ) = @_;
+ my $res = $self->app->($env);
+ my $path_match = $self->path;
+ my $path = $env->{'PATH_INFO'};
+ for ($path) {
+ my $matched = 'CODE' eq ref $path_match ?
+ $path_match->($_, $env)
+ : $_ =~ $path_match;
+ return $res unless $matched;
+ return $self->response_cb( $res,
+ sub {
+ my $res = shift;
+ my $headers = $res->[1];
+ my $time = 30 * 24 * 60 * 60;
+ my $expires = RT::Date->new(RT->SystemUser);
+ $expires->SetToNow;
+ $expires->AddSeconds($time);
+ Plack::Util::header_set($headers,
+ Expires => $expires->RFC2616,
+ );
+ Plack::Util::header_set($headers,
+ 'Cache-Control' => sprintf("max-age=%d, public", $time),
+ );
+ }
+ );
+ }
+}
+
+1;
diff --git a/t/web/helpers-http-cache-headers.t b/t/web/helpers-http-cache-headers.t
index 74008ec..c32782c 100644
--- a/t/web/helpers-http-cache-headers.t
+++ b/t/web/helpers-http-cache-headers.t
@@ -24,7 +24,10 @@ ok $m->login, 'logged in';
my $docroot = join '/', qw(share html);
# find endpoints to loop over
-my @endpoints = ("/NoAuth/css/aileron/squished-".("0"x32).".css");
+my @endpoints = (
+ "/NoAuth/css/aileron/squished-".("0"x32).".css",
+ '/static/images/bpslogo.png',
+);
find({
wanted => sub {
if ( -f $_ && $_ !~ m|autohandler$| ) {
@@ -77,7 +80,7 @@ foreach my $endpoint ( @endpoints ) {
my $header_key = 'default';
if ( $endpoint =~ m|Autocomplete| ) {
$header_key = 'Autocomplete';
- } elsif ( $endpoint =~ m|NoAuth| ) {
+ } elsif ( $endpoint =~ m/NoAuth|static/ ) {
$header_key = 'NoAuth';
}
my $headers = $expected->{$header_key};
-----------------------------------------------------------------------
More information about the rt-commit
mailing list