Accept range end position which exceededs the resource size
RFC 2616 14.35.1 Byte Ranges
If the last-byte-pos value is absent, or if the value is greater than
or equal to the current length of the entity-body, last-byte-pos is
taken to be equal to one less than the current length of the entity-
body in bytes.
This work is originally done by @shino
Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/d273c0cf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/d273c0cf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/d273c0cf
Branch: refs/heads/upstream
Commit: d273c0cf2f0da77e81566bcaaa5cf573243fca68
Parents: 2a91f6a
Author: UENISHI Kota <[email protected]>
Authored: Fri Jan 16 16:22:54 2015 +0900
Committer: UENISHI Kota <[email protected]>
Committed: Fri Jan 16 16:22:54 2015 +0900
----------------------------------------------------------------------
src/mochiweb_http.erl | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/d273c0cf/src/mochiweb_http.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_http.erl b/src/mochiweb_http.erl
index 4730446..24bf28c 100644
--- a/src/mochiweb_http.erl
+++ b/src/mochiweb_http.erl
@@ -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,
@@ -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
@@ -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("")),
@@ -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)),
@@ -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.