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