Skip to content

Commit

Permalink
fixed small bug where "chunked" would not always be the default trans…
Browse files Browse the repository at this point in the history
…fer encoding
  • Loading branch information
kraih committed Nov 6, 2012
1 parent 2cbbf8f commit 0148799
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -6,6 +6,8 @@
- Improved tests.
- Fixed bug that prevented around_dispatch hooks from working correctly in
embedded applications.
- Fixed small bug where "chunked" would not always be the default transfer
encoding.

3.54 2012-11-01
- Added next and previous methods to Mojo::DOM.
Expand Down
10 changes: 3 additions & 7 deletions lib/Mojo/Content.pm
Expand Up @@ -72,9 +72,9 @@ sub has_leftovers { !!length shift->leftovers }

sub header_size { length shift->build_headers }

sub is_chunked { (shift->headers->transfer_encoding || '') =~ /chunked/i }
sub is_chunked { !!shift->headers->transfer_encoding }

sub is_compressed { (shift->headers->content_encoding || '') eq 'gzip' }
sub is_compressed { (shift->headers->content_encoding || '') =~ /^gzip$/i }

sub is_dynamic {
my $self = shift;
Expand Down Expand Up @@ -291,11 +291,7 @@ sub _parse_chunked_trailing_headers {
$self->{chunk_state} = 'finished';

# Replace Transfer-Encoding with Content-Length
my $encoding = $headers->transfer_encoding;
$encoding =~ s/,?\s*chunked//ig;
$encoding
? $headers->transfer_encoding($encoding)
: $headers->remove('Transfer-Encoding');
$headers->remove('Transfer-Encoding');
$headers->content_length($self->{real_size}) unless $headers->content_length;
}

Expand Down
2 changes: 1 addition & 1 deletion t/mojo/request.t
Expand Up @@ -612,7 +612,7 @@ is $req->param('test23'), undef, 'no value';
$req = Mojo::Message::Request->new;
$req->parse("POST /foo/bar/baz.html?foo=13&bar=23#23 HTTP/1.1\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
$req->parse("Transfer-Encoding: chunked\x0d\x0a");
$req->parse("Transfer-Encoding: whatever\x0d\x0a");
$req->parse("Trailer: X-Trailer1; X-Trailer2\x0d\x0a\x0d\x0a");
$req->parse("4\x0d\x0a");
$req->parse("abcd\x0d\x0a");
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/response.t
Expand Up @@ -446,7 +446,7 @@ $res = Mojo::Message::Response->new;
$res->parse("HTTP/1.1 200 OK\x0d\x0a");
$res->parse("Content-Type: text/plain\x0d\x0a");
$res->parse("Content-Length: @{[length $compressed]}\x0d\x0a");
$res->parse("Content-Encoding: gzip\x0d\x0a\x0d\x0a");
$res->parse("Content-Encoding: GZip\x0d\x0a\x0d\x0a");
ok $res->content->is_compressed, 'content is compressed';
is $res->content->progress, 0, 'right progress';
$res->parse(substr $compressed, 0, 1);
Expand Down

0 comments on commit 0148799

Please sign in to comment.