- local *__ANON__ = 'mangle_request_middleware';
- my $env = $_[0];
- my ($number, $word) = (qr,(\d+),a, qr,(\w+),a);
- for ($env->{PATH_INFO}) {
- $env->{'gruntmaster.page'} = $1 if s,/page/$number$,/,;
- $env->{'gruntmaster.problem'} = $1 if s,^/pb/$word/,/,;
- $env->{'gruntmaster.contest'} = $1 if s,^/ct/$word/,/,;
- $env->{'gruntmaster.user'} = $1 if s,^/us/$word/,/,;
- $env->{'gruntmaster.page'} //= -1 if m,^/log/$,;
- }
- $app->($env);
- }
-}
-
-my %authen_cache;
-
-sub authenticate {
- my ($user, $pass, $env) = @_;
- my $cache_key = sha256 "$user:$pass";
- my $time = $authen_cache{$cache_key} // 0;
- if ($time >= time - 300) {
- return 1;
- } else {
- delete $authen_cache{$cache_key};
+ my $resp = $app->($_[0]);
+ my $hdrs = Plack::Util::headers($resp->[1]);
+ $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
+ $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
+ $resp->[1] = $hdrs->headers;
+ $resp;