Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
slightly better test case
  • Loading branch information
kraih committed Jun 3, 2014
1 parent 079514f commit 745a67c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Content.pm
Expand Up @@ -114,7 +114,8 @@ sub parse {

# Relaxed parsing
my $headers = $self->headers;
if ($self->auto_relax && !length($headers->content_length // '')) {
my $len = $headers->content_length // '';
if ($self->auto_relax && !length $len) {
my $connection = lc($headers->connection // '');
$self->relaxed(1)
if $connection eq 'close' || (!$connection && $self->expect_close);
Expand All @@ -129,9 +130,8 @@ sub parse {

# Normal content
else {
my $len = $headers->content_length || 0;
$self->{size} ||= 0;
if ((my $need = $len - $self->{size}) > 0) {
if ((my $need = ($len ||= 0) - $self->{size}) > 0) {
my $len = length $self->{buffer};
my $chunk = substr $self->{buffer}, 0, $need > $len ? $len : $need, '';
$self->_uncompress($chunk);
Expand Down
5 changes: 2 additions & 3 deletions t/mojo/response.t
Expand Up @@ -200,14 +200,13 @@ is $res->body, "Hello World!\n1234\nlalalala\n", 'right content';
$res = Mojo::Message::Response->new;
$res->parse("HTTP/1.0 500 Internal Server Error\x0d\x0a");
$res->parse("Connection: keep-alive\x0d\x0a\x0d\x0a");
$res->parse("HTTP/1.0 200 Internal Server Error\x0d\x0a\x0d\x0a");
$res->parse("HTTP/1.0 200 OK\x0d\x0a\x0d\x0a");
ok $res->is_finished, 'response is finished';
is $res->code, 500, 'right status';
is $res->message, 'Internal Server Error', 'right message';
is $res->version, '1.0', 'right version';
is $res->body, '', 'no content';
is $res->content->leftovers,
"HTTP/1.0 200 Internal Server Error\x0d\x0a\x0d\x0a",
is $res->content->leftovers, "HTTP/1.0 200 OK\x0d\x0a\x0d\x0a",
'next response in leftovers';

# Parse full HTTP 1.0 response (no limit)
Expand Down

0 comments on commit 745a67c

Please sign in to comment.