Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
made example more readable
  • Loading branch information
kraih committed Oct 7, 2011
1 parent 8a7a7d6 commit bd49360
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions t/mojolicious/upload_stream_lite_app.t
Expand Up @@ -26,32 +26,32 @@ app->hook(

# Check if we've reached the body yet
return unless $req->content->is_parsing_body;
$req->on_progress(sub { });

# Trigger early request for streaming uploads
# Trigger early request for everything under "/upload"
$tx->on_request->($tx) if $req->url->path->parts ~~ ['upload'];
}
);
}
);

# POST /upload
my $uploads = {};
my $cache = {};
post '/upload' => sub {
my $self = shift;

# First invocation, prepare streaming upload
$self->req->body(sub { $uploads->{shift->url->query->param('id')} .= pop });
return unless $self->req->is_done;
my $id = $self->param('id');
$self->req->body(sub { $cache->{$id} .= pop });
return unless $self->req->on_progress(undef)->is_done;

# Second invocation, render response
$self->render(data => $uploads->{$self->param('id')});
$self->render(data => $cache->{$id});
};

# GET /download
get '/download' => sub {
my $self = shift;
$self->render(data => $uploads->{$self->param('id')});
$self->render(data => $cache->{$self->param('id')});
};

my $t = Test::Mojo->new;
Expand Down

0 comments on commit bd49360

Please sign in to comment.