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