| 1 | package Terse::Plugin::Headers; | ||
| 2 | |||
| 3 | use base 'Terse::Plugin'; | ||
| 4 | |||
| 5 | sub build_plugin { | ||
| 6 | my ($self) = @_; | ||
| 7 | $self->default_headers = { | ||
| 8 | 'Strict-Transport-Sercurity' => 'max-age=3600', | ||
| 9 | 'X-Content-Security-Policy' => "default-src 'self'", | ||
| 10 | 'X-Content-Type-Options' => 'nosniff', | ||
| 11 | 'X-Download-Options' => 'noopen', | ||
| 12 | 'X-XSS-Protection' => 1, | ||
| 13 | 'Server' => 'guess', | ||
| 14 | 'Cache-Control' => 'no-cache, no-store', | ||
| 15 | 'Pragma' => 'no-cache' | ||
| 16 | }; | ||
| 17 | return $self; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub set { | ||
| 21 | my ($self, $t, %headers) = @_; | ||
| 22 | $t->headers({ | ||
| 23 | %{ $self->default_headers }, | ||
| 24 | %headers | ||
| 25 | }); | ||
| 26 | return $self; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Terse::Plugin::Headers - Terse headers | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | =head1 VERSION | ||
| 38 | |||
| 39 | Version 0.02 | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | =head1 SYNOPSIS | ||
| 44 | |||
| 45 | package MyApp::Plugin::Headers; | ||
| 46 | |||
| 47 | use base 'Terse::Plugin::Headers'; | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | package MyApp; | ||
| 52 | |||
| 53 | use base 'Terse::App'; | ||
| 54 | |||
| 55 | sub auth { | ||
| 56 | my ($self, $context) = @_; | ||
| 57 | if ($context->req) { # second run through of the auth sub routine | ||
| 58 | $context->plugin('headers')->set($context, %headers); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | =head1 LICENSE AND COPYRIGHT | ||
| 67 | |||
| 68 | L<Terse::Static>. | ||
| 69 | |||
| 70 | =cut |