Commit 0d670939 authored by Martijn Pieters's avatar Martijn Pieters

Merge HTTP Ranges fix from Zope 2.4 branch

parent d1596f3e
......@@ -274,9 +274,6 @@ class TestRequestRange(unittest.TestCase):
# A satisfiable and an unsatisfiable range
self.expectSingleRange('-0,3-23', 3, 24)
def testAdjacentRanges(self):
self.expectSingleRange('21-25,10-20', 10, 26)
def testEndOverflow(self):
l = len(self.data)
start, end = l - 10, l + 10
......@@ -301,6 +298,9 @@ class TestRequestRange(unittest.TestCase):
self.expectSingleRange(range, start, len(self.data))
# Multiple ranges
def testAdjacentRanges(self):
self.expectMultipleRanges('21-25,10-20', [(10, 21), (21, 26)])
def testMultipleRanges(self):
self.expectMultipleRanges('3-7,10-15', [(3, 8), (10, 16)])
......@@ -320,10 +320,10 @@ class TestRequestRange(unittest.TestCase):
def testIllegalIfRange(self):
# We assume that an illegal if-range is to be ignored, just like an
# illegal if-modified since.
self.expectSingleRange('21-25,10-20', 10, 26, if_range='garbage')
self.expectSingleRange('21-25,10-21', 10, 26, if_range='garbage')
def testEqualIfRangeDate(self):
self.expectSingleRange('21-25,10-20', 10, 26,
self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.createLastModifiedDate())
def testIsModifiedIfRangeDate(self):
......@@ -331,11 +331,11 @@ class TestRequestRange(unittest.TestCase):
if_range=self.createLastModifiedDate(offset=-100))
def testIsNotModifiedIfRangeDate(self):
self.expectSingleRange('21-25,10-20', 10, 26,
self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.createLastModifiedDate(offset=100))
def testEqualIfRangeEtag(self):
self.expectSingleRange('21-25,10-20', 10, 26,
self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.file.http__etag())
def testNotEqualIfRangeEtag(self):
......
......@@ -100,9 +100,8 @@ def optimizeRanges(ranges, size):
"""Optimize Range sets, given those sets and the length of the resource.
Optimisation is done by first expanding relative start values and open
ends, then sorting and combining overlapping or adjacent ranges. We also
remove unsatisfiable ranges (where the start lies beyond the size of the
resource).
ends, then sorting and combining overlapping ranges. We also remove
unsatisfiable ranges (where the start lies beyond the size of the resource).
"""
......@@ -126,8 +125,8 @@ def optimizeRanges(ranges, size):
while ranges:
nextstart, nextend = ranges.pop()
# If the next range overlaps or is adjacent
if nextstart <= end:
# If the next range overlaps
if nextstart < end:
# If it falls within the current range, discard
if nextend <= end:
continue
......
......@@ -113,10 +113,10 @@ class TestOptimizeRanges(unittest.TestCase):
def testAdjacentInOrder(self):
self.expectSets([(1, 10), (10, 20), (25, 50)], 5000,
[(1, 20), (25, 50)])
[(1, 10), (10, 20), (25, 50)])
def testAdjacentOutOfOrder(self):
self.expectSets([(-5, None), (40, 45)], 50, [(40, 50)])
self.expectSets([(-5, None), (40, 45)], 50, [(40, 45), (45, 50)])
def testOverLapAndOverflow(self):
# Note that one endpoint lies beyond the end.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment