Skip to content

Commit

Permalink
added a few more methods to Mojo::Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 24, 2014
1 parent ef0b424 commit 3d971e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Changes
@@ -1,6 +1,7 @@

5.55 2014-10-24
- Added content_location method to Mojo::Headers.
5.55 2014-10-25
- Added access_control_allow_origin, content_language, content_location and
strict_transport_security methods to Mojo::Headers.

5.54 2014-10-23
- Deprecated Object-Oriented Mojo::JSON API.
Expand Down
39 changes: 31 additions & 8 deletions lib/Mojo/Headers.pm
Expand Up @@ -8,14 +8,14 @@ has max_line_size => sub { $ENV{MOJO_MAX_LINE_SIZE} || 10240 };
# Common headers
my %NORMALCASE = map { lc($_) => $_ } (
qw(Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges),
qw(Allow Authorization Cache-Control Connection Content-Disposition),
qw(Content-Encoding Content-Length Content-Location Content-Range),
qw(Content-Type Cookie DNT Date ETag Expect Expires Host If-Modified-Since),
qw(If-None-Match 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 TE Trailer Transfer-Encoding Upgrade User-Agent Vary),
qw(WWW-Authenticate)
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)
);
for my $header (values %NORMALCASE) {
my $name = lc $header;
Expand Down Expand Up @@ -224,6 +224,14 @@ Shortcut for the C<Accept-Language> header.
Shortcut for the C<Accept-Ranges> header.
=head2 access_control_allow_origin
my $origin = $headers->access_control_allow_origin;
$headers = $headers->access_control_allow_origin('*');
Shortcut for the C<Access-Control-Allow-Origin> header from
L<Cross-Origin Resource Sharing|http://www.w3.org/TR/2010/WD-cors-20100727/>.
=head2 add
$headers = $headers->add(Foo => 'one value');
Expand Down Expand Up @@ -295,6 +303,13 @@ Shortcut for the C<Content-Disposition> header.
Shortcut for the C<Content-Encoding> header.
=head2 content_language
my $language = $headers->content_language;
$headers = $headers->content_language('en');
Shortcut for the C<Content-Language> header.
=head2 content_length
my $len = $headers->content_length;
Expand Down Expand Up @@ -566,6 +581,14 @@ L<RFC 6265|http://tools.ietf.org/html/rfc6265>.
Shortcut for the C<Status> header from
L<RFC 3875|http://tools.ietf.org/html/rfc3875>.
=head2 strict_transport_security
my $policy = $headers->strict_transport_security;
$headers = $headers->strict_transport_security('max-age=31536000');
Shortcut for the C<Strict-Transport-Security> header from
L<RFC 6797|http://tools.ietf.org/html/rfc6797>.
=head2 te
my $te = $headers->te;
Expand Down
19 changes: 12 additions & 7 deletions t/mojo/headers.t
Expand Up @@ -50,13 +50,16 @@ is $headers->accept_charset('foo')->accept_charset, 'foo', 'right value';
is $headers->accept_encoding('foo')->accept_encoding, 'foo', 'right value';
is $headers->accept_language('foo')->accept_language, 'foo', 'right value';
is $headers->accept_ranges('foo')->accept_ranges, 'foo', 'right value';
is $headers->allow('foo')->allow, 'foo', 'right value';
is $headers->authorization('foo')->authorization, 'foo', 'right value';
is $headers->connection('foo')->connection, 'foo', 'right value';
is $headers->cache_control('foo')->cache_control, 'foo', 'right value';
is $headers->access_control_allow_origin('foo')->access_control_allow_origin,
'foo', 'right value';
is $headers->allow('foo')->allow, 'foo', 'right value';
is $headers->authorization('foo')->authorization, 'foo', 'right value';
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';
Expand Down Expand Up @@ -87,9 +90,11 @@ is $headers->sec_websocket_protocol('foo')->sec_websocket_protocol, 'foo',
'right value';
is $headers->sec_websocket_version('foo')->sec_websocket_version, 'foo',
'right value';
is $headers->server('foo')->server, 'foo', 'right value';
is $headers->set_cookie('foo')->set_cookie, 'foo', 'right value';
is $headers->status('foo')->status, 'foo', 'right value';
is $headers->server('foo')->server, 'foo', 'right value';
is $headers->set_cookie('foo')->set_cookie, 'foo', 'right value';
is $headers->status('foo')->status, 'foo', 'right value';
is $headers->strict_transport_security('foo')->strict_transport_security,
'foo', 'right value';
is $headers->te('foo')->te, 'foo', 'right value';
is $headers->trailer('foo')->trailer, 'foo', 'right value';
is $headers->transfer_encoding('foo')->transfer_encoding, 'foo', 'right value';
Expand Down

0 comments on commit 3d971e1

Please sign in to comment.