Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept range end position which exceededs the resource size #147

Merged
merged 1 commit into from
Jan 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/mochiweb_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ after_response(Body, Req) ->
?MODULE:loop(Socket, Body)
end.

parse_range_request("bytes=0-") ->
undefined;
parse_range_request(RawRange) when is_list(RawRange) ->
try
"bytes=" ++ RangeString = RawRange,
Expand Down Expand Up @@ -169,7 +167,7 @@ range_skip_length(Spec, Size) ->
{R, Size - R};
{_OutOfRange, none} ->
invalid_range;
{Start, End} when 0 =< Start, Start =< End, End < Size ->
{Start, End} when 0 =< Start, Start < Size, Start =< End ->
{Start, End - Start + 1};
{_OutOfRange, _End} ->
invalid_range
Expand All @@ -188,7 +186,7 @@ range_test() ->
?assertEqual([{none, 20}], parse_range_request("bytes=-20")),

%% trivial single range
?assertEqual(undefined, parse_range_request("bytes=0-")),
?assertEqual([{0, none}], parse_range_request("bytes=0-")),

%% invalid, single ranges
?assertEqual(fail, parse_range_request("")),
Expand Down Expand Up @@ -222,6 +220,7 @@ range_skip_length_test() ->
?assertEqual({BodySize, 0}, range_skip_length({none, 0}, BodySize)),
?assertEqual({0, BodySize}, range_skip_length({none, BodySize}, BodySize)),
?assertEqual({0, BodySize}, range_skip_length({0, none}, BodySize)),
?assertEqual({0, BodySize}, range_skip_length({0, BodySize + 1}, BodySize)),
BodySizeLess1 = BodySize - 1,
?assertEqual({BodySizeLess1, 1},
range_skip_length({BodySize - 1, none}, BodySize)),
Expand All @@ -245,6 +244,8 @@ range_skip_length_test() ->
range_skip_length({-1, none}, BodySize)),
?assertEqual(invalid_range,
range_skip_length({BodySize, none}, BodySize)),
?assertEqual(invalid_range,
range_skip_length({BodySize + 1, BodySize + 5}, BodySize)),
ok.

-endif.