]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Base.pm
Add Cache-Control to most requests
[gruntmaster-page.git] / lib / Gruntmaster / Page / Base.pm
index 0585985cc9bd09bf0462e87239bc8f17b6e730c9..cf7d2291587809652e8636c03d692692161ed4ae 100644 (file)
@@ -4,7 +4,6 @@ use 5.014000;
 use strict;
 use warnings;
 
-use Encode qw/encode/;
 use File::Slurp qw/read_file/;
 use HTML::Template::Compiled;
 
@@ -32,7 +31,7 @@ sub import {
                local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
                $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
        };
-       *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] };
+       *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] };
        *{"${caller}::purge"} = sub {
                return unless $ENV{PURGE_HOST};
                my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]");
@@ -84,7 +83,7 @@ my %orig_header_templates = (
 
 <div class="container-fluid">
 
-<div id="subtitle">TITLE_GOES_HERE</div>
+<h1 id="title">TITLE_GOES_HERE</h1>
 <div id="result"></div>
 HTML
 );
@@ -146,11 +145,15 @@ sub generate{
 
        my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',);
        $self->_generate($htc, $lang, @args);
-       [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ encode 'UTF-8' => $htc->output ] ]
+       my $out = $htc->output;
+       utf8::downgrade($out);
+       [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
 }
 
 sub _generate {}
 
+sub max_age { 60 }
+
 sub variants {
        [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ]
 }
This page took 0.018932 seconds and 4 git commands to generate.