Skip to content

Commit

Permalink
added origin and sec_websocket_extensions methods to Mojo::Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 15, 2012
1 parent 33161a5 commit e3f5bb0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Changes
@@ -1,7 +1,7 @@

3.31 2012-08-15
- Added accept_charset, accept_encoding and content_encoding methods to
Mojo::Headers.
- Added accept_charset, accept_encoding, content_encoding, origin and
sec_websocket_extensions methods to Mojo::Headers.
- Improved documentation.
- Improved tests.

Expand Down
29 changes: 18 additions & 11 deletions lib/Mojo/Headers.pm
Expand Up @@ -11,10 +11,10 @@ my @HEADERS = (
qw(Authorization Connection Cache-Control Content-Disposition),
qw(Content-Encoding Content-Length Content-Range Content-Type Cookie DNT),
qw(Date ETag Expect Expires Host If-Modified-Since Last-Modified Location),
qw(Proxy-Authenticate Proxy-Authorization Range Sec-WebSocket-Accept),
qw(Sec-WebSocket-Key Sec-WebSocket-Origin Sec-WebSocket-Protocol),
qw(Sec-WebSocket-Version Server Set-Cookie Status TE Trailer),
qw(Transfer-Encoding Upgrade User-Agent WWW-Authenticate)
qw(Origin Proxy-Authenticate Proxy-Authorization Range),
qw(Sec-WebSocket-Accept Sec-WebSocket-Extensions Sec-WebSocket-Key),
qw(Sec-WebSocket-Protocol Sec-WebSocket-Version Server Set-Cookie Status),
qw(TE Trailer Transfer-Encoding Upgrade User-Agent WWW-Authenticate)
);
{
no strict 'refs';
Expand Down Expand Up @@ -437,6 +437,13 @@ Shortcut for the C<Location> header.
Generate a list of all currently defined headers.
=head2 C<origin>
my $origin = $headers->origin;
$headers = $headers->origin('http://example.com');
Shortcut for the C<Origin> header.
=head2 C<parse>
$headers = $headers->parse("Content-Type: text/plain\r\n\r\n");
Expand Down Expand Up @@ -485,20 +492,20 @@ Remove a header.
Shortcut for the C<Sec-WebSocket-Accept> header.
=head2 C<sec_websocket_extensions>
my $extensions = $headers->sec_websocket_extensions;
$headers = $headers->sec_websocket_extensions('foo');
Shortcut for the C<Sec-WebSocket-Extensions> header.
=head2 C<sec_websocket_key>
my $key = $headers->sec_websocket_key;
$headers = $headers->sec_websocket_key('dGhlIHNhbXBsZSBub25jZQ==');
Shortcut for the C<Sec-WebSocket-Key> header.
=head2 C<sec_websocket_origin>
my $origin = $headers->sec_websocket_origin;
$headers = $headers->sec_websocket_origin('http://example.com');
Shortcut for the C<Sec-WebSocket-Origin> header.
=head2 C<sec_websocket_protocol>
my $protocol = $headers->sec_websocket_protocol;
Expand Down
9 changes: 5 additions & 4 deletions t/mojo/headers.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 92;
use Test::More tests => 93;

# "So, have a merry Christmas, a happy Hanukkah, a kwaazy Kwanza,
# a tip-top Tet, and a solemn, dignified, Ramadan.
Expand Down Expand Up @@ -73,16 +73,17 @@ is $headers->host('foo')->host, 'foo', 'right value';
is $headers->if_modified_since('foo')->if_modified_since, 'foo', 'right value';
is $headers->last_modified('foo')->last_modified, 'foo', 'right value';
is $headers->location('foo')->location, 'foo', 'right value';
is $headers->origin('foo')->origin, 'foo', 'right value';
is $headers->proxy_authenticate('foo')->proxy_authenticate, 'foo',
'right value';
is $headers->proxy_authorization('foo')->proxy_authorization, 'foo',
'right value';
is $headers->range('foo')->range, 'foo', 'right value';
is $headers->sec_websocket_protocol('foo')->sec_websocket_protocol, 'foo',
is $headers->sec_websocket_accept('foo')->sec_websocket_accept, 'foo',
'right value';
is $headers->sec_websocket_key('foo')->sec_websocket_key, 'foo', 'right value';
is $headers->sec_websocket_origin('foo')->sec_websocket_origin, 'foo',
is $headers->sec_websocket_extensions('foo')->sec_websocket_extensions, 'foo',
'right value';
is $headers->sec_websocket_key('foo')->sec_websocket_key, 'foo', 'right value';
is $headers->sec_websocket_protocol('foo')->sec_websocket_protocol, 'foo',
'right value';
is $headers->sec_websocket_version('foo')->sec_websocket_version, 'foo',
Expand Down

0 comments on commit e3f5bb0

Please sign in to comment.