Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix a case in handling range headers #85

Merged
merged 1 commit into from

2 participants

@pmundkur

The range-header handling does not implement the following:
http://tools.ietf.org/html/rfc2616#section-14.35.1

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.

Specifically, the 'greater than equal to' case.

@pmundkur pmundkur The range-header handling does not implement the following:
http://tools.ietf.org/html/rfc2616#section-14.35.1

  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.

Specifically, the 'greater than equal to' case.
fe5e0c5
@etrepum

End >= Size is a bit redundant here

Good catch. I can send you another pull with that cleaned up, unless you want more changes.

Owner

This is fine as-is, just was making a note of it.

@etrepum etrepum merged commit e282266 into mochi:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 8, 2012
  1. @pmundkur

    The range-header handling does not implement the following:

    pmundkur authored
    http://tools.ietf.org/html/rfc2616#section-14.35.1
    
      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.
    
    Specifically, the 'greater than equal to' case.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/mochiweb_http.erl
View
10 src/mochiweb_http.erl
@@ -171,6 +171,8 @@ range_skip_length(Spec, Size) ->
invalid_range;
{Start, End} when 0 =< Start, Start =< End, End < Size ->
{Start, End - Start + 1};
+ {Start, End} when 0 =< Start, Start =< End, End >= Size ->
+ {Start, Size - Start};
{_OutOfRange, _End} ->
invalid_range
end.
@@ -225,19 +227,23 @@ range_skip_length_test() ->
BodySizeLess1 = BodySize - 1,
?assertEqual({BodySizeLess1, 1},
range_skip_length({BodySize - 1, none}, BodySize)),
+ ?assertEqual({BodySizeLess1, 1},
+ range_skip_length({BodySize - 1, BodySize+5}, BodySize)),
+ ?assertEqual({BodySizeLess1, 1},
+ range_skip_length({BodySize - 1, BodySize}, BodySize)),
%% out of range, return whole thing
?assertEqual({0, BodySize},
range_skip_length({none, BodySize + 1}, BodySize)),
?assertEqual({0, BodySize},
range_skip_length({none, -1}, BodySize)),
+ ?assertEqual({0, BodySize},
+ range_skip_length({0, BodySize + 1}, BodySize)),
%% invalid ranges
?assertEqual(invalid_range,
range_skip_length({-1, 30}, BodySize)),
?assertEqual(invalid_range,
- range_skip_length({0, BodySize + 1}, BodySize)),
- ?assertEqual(invalid_range,
range_skip_length({-1, BodySize + 1}, BodySize)),
?assertEqual(invalid_range,
range_skip_length({BodySize, 40}, BodySize)),
Something went wrong with that request. Please try again.