use POSIX ();
use Gruntmaster::Data ();
use List::Util ();
+use LWP::UserAgent;
+
+my $ua = LWP::UserAgent->new;
sub import {
my $caller = caller;
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)
+ };
}
##################################################
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 {}
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 <css/*.css>;
- [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]] }
debug $env => "";
my $js;
$js .= read_file $_ for <js/*.js>;
- [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]] }
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';
}
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]] }