Skip to content
Open
Show file tree
Hide file tree
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: 7 additions & 2 deletions lib/net/http/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,14 @@ def set_range(r, e = nil)
when Range
first = r.first
last = r.end
last -= 1 if r.exclude_end?
if last.nil?
# An endless range such as 100.. runs to the end of the content.
last = -1
elsif r.exclude_end?
last -= 1
end
if last == -1
rangestr = (first > 0 ? "#{first}-" : "-#{-first}")
rangestr = (first >= 0 ? "#{first}-" : "-#{-first}")
else
raise Net::HTTPHeaderSyntaxError, 'range.first is negative' if first < 0
raise Net::HTTPHeaderSyntaxError, 'range.last is negative' if last < 0
Expand Down
13 changes: 13 additions & 0 deletions test/net/http/test_httpheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,19 @@ def test_range=
assert_equal 'bytes=0-499', @c['range']
end

def test_range_endless
@c.range = (100..)
assert_equal 'bytes=100-', @c['range']
@c.range = (100...)
assert_equal 'bytes=100-', @c['range']
@c.range = (0..)
assert_equal 'bytes=0-', @c['range']
@c.range = (-5..)
assert_equal 'bytes=-5', @c['range']
@c.range = 0..-1
assert_equal 'bytes=0-', @c['range']
end

def test_content_range
@c['Content-Range'] = "bytes 0-499/1000"
assert_equal 0..499, @c.content_range
Expand Down