[Rt-commit] rt branch, 4.2/cache-control-regression, repushed
Wallace Reis
wreis at bestpractical.com
Wed Mar 26 14:38:40 EDT 2014
The branch 4.2/cache-control-regression was deleted and repushed:
was df81b84b875e13ba86802bca52428be40889fdbb
now c2201cd01798f897e1b650372c17acd7f604d966
1: df81b84 ! 1: c2201cd I#28640: Set headers for static content
@@ -4,18 +4,105 @@
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,
+ (probably when started serving it with Static middleware). Additionally,
add support for static content served from custom StaticRoots.
+
+diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
+--- a/lib/RT/Interface/Web.pm
++++ b/lib/RT/Interface/Web.pm
+@@
+ use Encode qw();
+ use List::MoreUtils qw();
+ use JSON qw();
++use Plack::Util;
+
+ =head2 SquishedCSS $style
+
+@@
+ $HTML::Mason::Commands::m->abort;
+ }
+
+-=head2 CacheControlExpiresHeaders
++=head2 GetStaticHeaders
+
+-set both Cache-Control and Expires http headers
++return an arrayref of Headers (currently, Cache-Control and Expires).
+
+ =cut
+
+-sub CacheControlExpiresHeaders {
++sub GetStaticHeaders {
+ my %args = @_;
+
+ my $Visibility = 'private';
+@@
+ ? sprintf "max-age=%d, %s", $args{Time}, $Visibility
+ : 'no-cache'
+ ;
+- $HTML::Mason::Commands::r->headers_out->{'Cache-Control'} = $CacheControl;
+
+ my $expires = RT::Date->new(RT->SystemUser);
+ $expires->SetToNow;
+ $expires->AddSeconds( $args{Time} ) if $args{Time};
+
+- $HTML::Mason::Commands::r->headers_out->{'Expires'} = $expires->RFC2616;
++ return [
++ Expires => $expires->RFC2616,
++ 'Cache-Control' => $CacheControl,
++ ];
++}
++
++=head2 CacheControlExpiresHeaders
++
++set both Cache-Control and Expires http headers
++
++=cut
++
++sub CacheControlExpiresHeaders {
++ Plack::Util::header_iter( GetStaticHeaders(@_), sub {
++ my ( $key, $val ) = @_;
++ $HTML::Mason::Commands::r->headers_out->{$key} = $val;
++ } );
+ }
+
+ =head2 StaticFileHeaders
+@@
+ =cut
+
+ sub StaticFileHeaders {
+- my $date = RT::Date->new(RT->SystemUser);
+-
+ # remove any cookie headers -- if it is cached publicly, it
+ # shouldn't include anyone's cookie!
+ delete $HTML::Mason::Commands::r->err_headers_out->{'Set-Cookie'};
+
+ # Expire things in a month.
+ CacheControlExpiresHeaders( Time => 'forever' );
+-
+- # if we set 'Last-Modified' then browser request a comp using 'If-Modified-Since'
+- # request, but we don't handle it and generate full reply again
+- # Last modified at server start time
+- # $date->Set( Value => $^T );
+- # $HTML::Mason::Commands::r->headers_out->{'Last-Modified'} = $date->RFC2616;
+ }
+
+ =head2 ComponentPathIsSafe PATH
diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@
+ my $app = shift;
+ my $builder = Plack::Builder->new;
+
++ my $headers = RT::Interface::Web::GetStaticHeaders(Time => 'forever');
++
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'},
++ headers => $headers,
+ );
+ $builder->add_middleware(
'Plack::Middleware::Static',
@@ -29,6 +116,7 @@
+ $builder->add_middleware(
+ '+RT::Interface::Web::Middleware::StaticHeaders',
+ path => $path,
++ headers => $headers,
+ );
for my $root (RT::Interface::Web->StaticRoots) {
$builder->add_middleware(
@@ -51,7 +139,7 @@
+use base 'Plack::Middleware';
+use Plack::Util;
+
-+use Plack::Util::Accessor qw(path);
++use Plack::Util::Accessor qw(path headers);
+
+sub call {
+ my ( $self, $env ) = @_;
@@ -67,16 +155,9 @@
+ 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),
-+ );
++ Plack::Util::header_iter( $self->headers, sub {
++ Plack::Util::header_set($headers, @_);
++ } );
+ }
+ );
+ }
More information about the rt-commit
mailing list