Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add content_security_policy method to Mojo::Headers
  • Loading branch information
kraih committed Feb 3, 2015
1 parent 28652ad commit ce13a6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.77 2015-02-03
- Added content_security_policy method to Mojo::Headers.
- Fixed canonicalize in Mojo::Path to not remove parts with more than three
dots.

Expand Down
21 changes: 15 additions & 6 deletions lib/Mojo/Headers.pm
Expand Up @@ -11,12 +11,13 @@ my %NORMALCASE = map { lc($_) => $_ } (
qw(Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges),
qw(Access-Control-Allow-Origin Allow Authorization Cache-Control Connection),
qw(Content-Disposition Content-Encoding Content-Language Content-Length),
qw(Content-Location Content-Range Content-Type Cookie DNT Date ETag Expect),
qw(Expires Host If-Modified-Since If-None-Match Last-Modified Link Location),
qw(Origin Proxy-Authenticate Proxy-Authorization Range Sec-WebSocket-Accept),
qw(Sec-WebSocket-Extensions Sec-WebSocket-Key Sec-WebSocket-Protocol),
qw(Sec-WebSocket-Version Server Set-Cookie Status Strict-Transport-Security),
qw(TE Trailer Transfer-Encoding Upgrade User-Agent Vary WWW-Authenticate)
qw(Content-Location Content-Range Content-Security-Policy Content-Type),
qw(Cookie DNT Date ETag Expect Expires Host If-Modified-Since If-None-Match),
qw(Last-Modified Link Location Origin Proxy-Authenticate),
qw(Proxy-Authorization Range Sec-WebSocket-Accept Sec-WebSocket-Extensions),
qw(Sec-WebSocket-Key Sec-WebSocket-Protocol Sec-WebSocket-Version Server),
qw(Set-Cookie Status Strict-Transport-Security TE Trailer Transfer-Encoding),
qw(Upgrade User-Agent Vary WWW-Authenticate)
);
for my $header (values %NORMALCASE) {
my $name = lc $header;
Expand Down Expand Up @@ -341,6 +342,14 @@ Shortcut for the C<Content-Location> header.
Shortcut for the C<Content-Range> header.
=head2 content_security_policy
my $policy = $headers->content_security_policy;
$headers = $headers->content_security_policy('default-src https:');
Shortcut for the C<Content-Security-Policy> header from
L<Content Security Policy 1.0|http://www.w3.org/TR/CSP/>.
=head2 content_type
my $type = $headers->content_type;
Expand Down
12 changes: 7 additions & 5 deletions t/mojo/headers.t
Expand Up @@ -58,11 +58,13 @@ is $headers->connection('foo')->connection, 'foo', 'right value';
is $headers->cache_control('foo')->cache_control, 'foo', 'right value';
is $headers->content_disposition('foo')->content_disposition, 'foo',
'right value';
is $headers->content_encoding('foo')->content_encoding, 'foo', 'right value';
is $headers->content_language('foo')->content_language, 'foo', 'right value';
is $headers->content_length('foo')->content_length, 'foo', 'right value';
is $headers->content_location('foo')->content_location, 'foo', 'right value';
is $headers->content_range('foo')->content_range, 'foo', 'right value';
is $headers->content_encoding('foo')->content_encoding, 'foo', 'right value';
is $headers->content_language('foo')->content_language, 'foo', 'right value';
is $headers->content_length('foo')->content_length, 'foo', 'right value';
is $headers->content_location('foo')->content_location, 'foo', 'right value';
is $headers->content_range('foo')->content_range, 'foo', 'right value';
is $headers->content_security_policy('foo')->content_security_policy, 'foo',
'right value';
is $headers->content_type('foo')->content_type, 'foo', 'right value';
is $headers->cookie('foo')->cookie, 'foo', 'right value';
is $headers->dnt('foo')->dnt, 'foo', 'right value';
Expand Down

0 comments on commit ce13a6a

Please sign in to comment.