Skip to content

Commit

Permalink
fix bug in Mojo::Message where multipart content would get downgraded…
Browse files Browse the repository at this point in the history
… unnecessarily (closes #807)
  • Loading branch information
kraih committed Jun 9, 2015
1 parent 5a00d9e commit 943779a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,6 +1,8 @@

6.12 2015-05-30
6.12 2015-06-09
- Added TO_JSON method to Mojo::Collection. (wttw)
- Fixed bug in Mojo::Message where multipart content would get downgraded
unnecessarily.

6.11 2015-05-16
- Deprecated Mojo::Content::build_body and Mojo::Content::build_headers.
Expand Down
10 changes: 4 additions & 6 deletions lib/Mojo/Message.pm
Expand Up @@ -20,15 +20,13 @@ has version => '1.1';
sub body {
my $self = shift;

# Multipart content needs to be downgraded
# Get
my $content = $self->content;
return $content->is_multipart ? '' : $content->asset->slurp unless @_;

# Set (multipart content needs to be downgraded)
$content = $self->content(Mojo::Content::Single->new)->content
if $content->is_multipart;

# Get
return $content->asset->slurp unless @_;

# Set
$content->asset(Mojo::Asset::Memory->new->add_chunk(@_));

return $self;
Expand Down
2 changes: 2 additions & 0 deletions t/mojo/request.t
Expand Up @@ -741,6 +741,7 @@ $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
is $req->content->progress, 416, 'right progress';
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'multipart content';
is $req->body, '', 'no content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
Expand Down Expand Up @@ -808,6 +809,7 @@ $req->parse("Content-Type: application/octet-stream\x0d\x0a\x0d\x0a");
$req->parse("Bye!\x0d\x0a------------0xKhTmLbOuNdArY--");
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'multipart content';
is $req->body, '', 'no content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
Expand Down

0 comments on commit 943779a

Please sign in to comment.