Skip to content

Commit

Permalink
better range support
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 20, 2012
1 parent 77c38c0 commit 4aa1082
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Static.pm
Expand Up @@ -83,7 +83,7 @@ sub serve_asset {
# Not satisfiable
return $res->code(416) unless $size && $range =~ m/^bytes=(\d+)?-(\d+)?/;
$start = $1 if defined $1;
$end = $2 if defined $2;
$end = $2 if defined $2 && $2 <= $end;
return $res->code(416) if $start > $end || $end > ($size - 1);

# Satisfiable
Expand Down
8 changes: 8 additions & 0 deletions t/mojolicious/static_lite_app.t
Expand Up @@ -65,6 +65,14 @@ $t->get_ok('/hello.txt' => {Range => 'bytes=0-0'})->status_is(206)
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 1)
->header_is('Content-Range' => 'bytes 0-0/31')->content_is('H');

# GET /hello.txt (partial static file, end outside of range)
$t->get_ok('/hello.txt' => {Range => 'bytes=25-35'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Content-Length' => 6)
->header_is('Content-Range' => 'bytes 25-30/31')
->header_is('Accept-Ranges' => 'bytes')->content_is("file!\n");

# GET /hello.txt (partial static file, invalid range)
$t->get_ok('/hello.txt' => {Range => 'bytes=32-33'})->status_is(416)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down

0 comments on commit 4aa1082

Please sign in to comment.