Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed upgrade event timing
  • Loading branch information
kraih committed Nov 9, 2011
1 parent 871d0f5 commit 84bc09d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 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.26 2011-11-09 00:00:00
- Added EXPERIMENTAL upgrade event to Mojo::Asset::Memory.
- Improved documentation.

2.25 2011-11-08 00:00:00
- Removed canonicalize method from Mojo::URL.
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -20,9 +20,8 @@ sub add_chunk {
my ($self, $chunk) = @_;
$self->{content} .= $chunk if defined $chunk;
return $self unless $self->size > $self->max_memory_size;
my $file = Mojo::Asset::File->new->add_chunk($self->slurp);
$self->emit(upgrade => $file);
return $file;
$self->emit(upgrade => my $file = Mojo::Asset::File->new);
return $file->add_chunk($self->slurp);
}

sub contains {
Expand Down
11 changes: 1 addition & 10 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -124,16 +124,7 @@ sub is_multipart {1}

sub parse {
my $self = shift;

# Parse headers and chunked body
$self->SUPER::parse(@_);

# Custom body parser
return $self if $self->has_subscribers('read');

# Parse multipart content
$self->_parse_multipart;

$self->SUPER::parse(@_)->_parse_multipart;
return $self;
}

Expand Down
16 changes: 11 additions & 5 deletions t/mojo/request.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 909;
use Test::More tests => 910;

# "When will I learn?
# The answer to life's problems aren't at the bottom of a bottle,
Expand Down Expand Up @@ -308,8 +308,13 @@ is $req->headers->content_length, undef, 'no "Content-Length" value';
my $backup = $ENV{MOJO_MAX_MEMORY_SIZE} || '';
$ENV{MOJO_MAX_MEMORY_SIZE} = 12;
$req = Mojo::Message::Request->new;
my $upgrade;
$req->content->asset->on(upgrade => sub { $upgrade = pop->is_file });
my @upgrade;
$req->content->asset->on(
upgrade => sub {
my ($mem, $file) = @_;
@upgrade = ($file->is_file, $file->size);
}
);
is $req->content->progress, 0, 'right progress';
$req->parse('GET /foo/bar/baz.html?fo');
is $req->content->progress, 0, 'right progress';
Expand All @@ -319,9 +324,10 @@ is $req->content->progress, 0, 'right progress';
$req->parse("plain\x0d\x0aContent-Length: 27\x0d\x0a\x0d\x0aHell");
is $req->content->progress, 4, 'right progress';
ok !$req->content->asset->is_file, 'stored in memory';
ok !$upgrade, 'upgrade event has not been emitted';
ok !$upgrade[0], 'upgrade event has not been emitted';
$req->parse("o World!\n");
ok $upgrade, 'upgrade event has been emitted';
ok $upgrade[0], 'upgrade event has been emitted';
ok !$upgrade[1], 'file was empty when upgrade event got emitted';
is $req->content->progress, 13, 'right progress';
ok $req->content->asset->is_file, 'stored in file';
$req->parse("1234\nlalalala\n");
Expand Down

0 comments on commit 84bc09d

Please sign in to comment.