Skip to content

Commit

Permalink
fixed small parser bug in Mojo::Message::Response
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 19, 2012
1 parent 556c3e0 commit 932935f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Mojolicious.

2.46 2012-01-19 00:00:00
- Improved documentation.
- Fixed small parser bug in Mojo::Message::Response.

2.45 2012-01-18 00:00:00
- Removed T-Shirt link.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Message/Response.pm
Expand Up @@ -9,11 +9,11 @@ has [qw/code message/];

my $START_LINE_RE = qr|
^\s*
HTTP/(\d\.\d) # Version
HTTP/(\d\.\d) # Version
\s+
(\d\d\d) # Code
(\d\d\d) # Code
\s*
([\w\'\s]+)? # Message (with "I'm a teapot" support)
([^\x0d\x0a]+)? # Message (with "I'm a teapot" support)
$
|x;

Expand Down
27 changes: 26 additions & 1 deletion t/mojo/response.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 269;
use Test::More tests => 283;

# "Quick Smithers. Bring the mind eraser device!
# You mean the revolver, sir?
Expand Down Expand Up @@ -38,6 +38,16 @@ is $res->version, '1.1', 'right version';
ok $res->at_least_version('1.0'), 'at least version 1.0';
ok !$res->at_least_version('1.2'), 'not version 1.2';

# Parse HTTP 1.1 response start line, no headers and body (strange message)
$res = Mojo::Message::Response->new;
$res->parse("HTTP/1.1 200 Looks-0k!\@ #\$\%^ &*()\x0d\x0a\x0d\x0a");
ok $res->is_finished, 'response is finished';
is $res->code, 200, 'right status';
is $res->message, 'Looks-0k!@ #$%^ &*()', 'right message';
is $res->version, '1.1', 'right version';
ok $res->at_least_version('1.0'), 'at least version 1.0';
ok !$res->at_least_version('1.2'), 'not version 1.2';

# Parse HTTP 1.1 response start line, no headers and body (small chunks)
$res = Mojo::Message::Response->new;
$res->parse('H');
Expand Down Expand Up @@ -293,6 +303,21 @@ ok !$res->at_least_version('1.2'), 'not version 1.2';
is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value';
is $res->headers->content_length, 0, 'right "Content-Length" value';

# Build HTTP 1.1 response start line with minimal headers (strange message)
$res = Mojo::Message::Response->new;
$res->code(404);
$res->message('Looks-0k!@ #$%^ &*()');
$res->headers->date('Sun, 17 Aug 2008 16:27:35 GMT');
$res = Mojo::Message::Response->new->parse($res->to_string);
ok $res->is_finished, 'response is finished';
is $res->code, '404', 'right status';
is $res->message, 'Looks-0k!@ #$%^ &*()', 'right message';
is $res->version, '1.1', 'right version';
ok $res->at_least_version('1.0'), 'at least version 1.0';
ok !$res->at_least_version('1.2'), 'not version 1.2';
is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value';
is $res->headers->content_length, 0, 'right "Content-Length" value';

# Build HTTP 1.1 response start line and header
$res = Mojo::Message::Response->new;
$res->code(200);
Expand Down

0 comments on commit 932935f

Please sign in to comment.