From: Marius Gavrilescu Date: Thu, 6 Feb 2014 10:46:59 +0000 (+0200) Subject: Add X-Forever X-Git-Url: http://git.ieval.ro/?p=gruntmaster-page.git;a=commitdiff_plain;h=49c1467ab6c3bfeb9aeba883d29a7be7dfefe93e Add X-Forever --- diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index bc8e9ce..0585985 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -13,6 +13,9 @@ use HTML::Template::Compiled; use POSIX (); use Gruntmaster::Data (); use List::Util (); +use LWP::UserAgent; + +my $ua = LWP::UserAgent->new; sub import { my $caller = caller; @@ -29,8 +32,12 @@ 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'], [ @_ ] ] }; + *{"${caller}::purge"} = sub { + return unless $ENV{PURGE_HOST}; + my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]"); + $ua->request($req) + }; } ################################################## @@ -139,7 +146,7 @@ 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'], [ encode 'UTF-8' => $htc->output ] ] + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ encode 'UTF-8' => $htc->output ] ] } sub _generate {} diff --git a/lib/Gruntmaster/Page/CSS.pm b/lib/Gruntmaster/Page/CSS.pm index 25b6137..2553ab6 100644 --- a/lib/Gruntmaster/Page/CSS.pm +++ b/lib/Gruntmaster/Page/CSS.pm @@ -16,7 +16,7 @@ sub generate{ return [404, ['Content-Type' => 'text/plain'], [ 'Not found' ]] unless -e "css/themes/$theme.css"; my $css = read_file "css/themes/$theme.css"; $css .= read_file $_ for ; - [200, ['Content-Type' => 'text/css', 'Cache-Control' => 'public, max-age=604800'], [minify $css] ] + [200, ['Content-Type' => 'text/css', 'Cache-Control' => 'public, max-age=604800', 'X-Forever' => 1], [minify $css] ] } sub variants{ [[css => 1, 'text/css', undef, undef, undef, undef]] } diff --git a/lib/Gruntmaster/Page/JS.pm b/lib/Gruntmaster/Page/JS.pm index dca5aff..9e78192 100644 --- a/lib/Gruntmaster/Page/JS.pm +++ b/lib/Gruntmaster/Page/JS.pm @@ -15,7 +15,7 @@ sub generate{ debug $env => ""; my $js; $js .= read_file $_ for ; - [200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'public, max-age=604800'], [$js] ] + [200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'public, max-age=604800', 'X-Forever' => 1], [$js] ] } sub variants{ [[js => 1, 'application/javascript', undef, undef, undef, undef]] } diff --git a/lib/Gruntmaster/Page/Register.pm b/lib/Gruntmaster/Page/Register.pm index 4b93a84..dcb9451 100644 --- a/lib/Gruntmaster/Page/Register.pm +++ b/lib/Gruntmaster/Page/Register.pm @@ -23,8 +23,7 @@ sub generate{ insert_user $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level; - #PUBLISH genpage => "us/index.html"; - #PUBLISH genpage => "us/$username.html"; + purge "/us/"; reply 'Registered successfully'; } diff --git a/lib/Gruntmaster/Page/Src.pm b/lib/Gruntmaster/Page/Src.pm index b7b9433..8e51d8b 100644 --- a/lib/Gruntmaster/Page/Src.pm +++ b/lib/Gruntmaster/Page/Src.pm @@ -22,7 +22,7 @@ sub generate{ debug $env => "Contest is $ct, job is $job and extension is $ext"; local $Gruntmaster::Data::contest = $ct if $ct; - [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800'], [job_inmeta($job)->{files}{prog}{content}] ] + [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800', 'X-Forever' => 1], [job_inmeta($job)->{files}{prog}{content}] ] } sub variants{ [[file => 1, undef, undef, undef, undef, undef]] }