Commit 6945b4f5 authored by Martijn Pieters's avatar Martijn Pieters

Merge HTP Range fix from trunk.

parent 9c9aafa1
......@@ -12,7 +12,7 @@
##############################################################################
"""Image object"""
__version__='$Revision: 1.133 $'[11:-2]
__version__='$Revision: 1.134 $'[11:-2]
import Globals, string, struct
from OFS.content_types import guess_content_type
......@@ -171,6 +171,11 @@ class File(Persistent, Implicit, PropertyManager,
# HTTP Range header handling
range = REQUEST.get_header('Range', None)
request_range = REQUEST.get_header('Request-Range', None)
if request_range is not None:
# Netscape 2 through 4 and MSIE 3 implement a draft version
# Later on, we need to serve a different mime-type as well.
range = request_range
if_range = REQUEST.get_header('If-Range', None)
if range is not None:
ranges = HTTPRangeSupport.parseRange(range)
......@@ -284,12 +289,17 @@ class File(Persistent, Implicit, PropertyManager,
end - start)
# Some clients implement an earlier draft of the spec, they
# will only accept x-byteranges.
draftprefix = (request_range is not None) and 'x-' or ''
RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified',
rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type',
'multipart/byteranges; boundary=%s' % boundary)
'multipart/%sbyteranges; boundary=%s' % (
draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content
pos = 0
......
......@@ -171,7 +171,7 @@ class TestRequestRange(unittest.TestCase):
'Incorrect range returned, expected %s, got %s' % (
`self.data[start:end]`, `body`))
def expectMultipleRanges(self, range, sets,
def expectMultipleRanges(self, range, sets, draft=0,
rangeParse=re.compile('bytes\s*(\d+)-(\d+)/(\d+)')):
req = self.app.REQUEST
rsp = req.RESPONSE
......@@ -179,6 +179,9 @@ class TestRequestRange(unittest.TestCase):
# Add headers
req.environ['HTTP_RANGE'] = 'bytes=%s' % range
if draft:
req.environ['HTTP_REQUEST_RANGE'] = 'bytes=%s' % range
body = self.doGET(req, rsp)
self.failUnless(rsp.getStatus() == 206,
......@@ -187,9 +190,10 @@ class TestRequestRange(unittest.TestCase):
'The Content-Range header should not be set!')
ct = string.split(rsp.getHeader('content-type'), ';')[0]
self.failIf(ct != 'multipart/byteranges',
"Incorrect Content-Type set. Expected 'multipart/byteranges', "
"got %s" % ct)
draftprefix = draft and 'x-' or ''
self.failIf(ct != 'multipart/%sbyteranges' % draftprefix,
"Incorrect Content-Type set. Expected 'multipart/%sbyteranges', "
"got %s" % (draftprefix, ct))
if rsp.getHeader('content-length'):
self.failIf(rsp.getHeader('content-length') != len(body),
'Incorrect Content-Length is set! Expected %d, got %d.' % (
......@@ -304,6 +308,9 @@ class TestRequestRange(unittest.TestCase):
def testMultipleRanges(self):
self.expectMultipleRanges('3-7,10-15', [(3, 8), (10, 16)])
def testMultipleRangesDraft(self):
self.expectMultipleRanges('3-7,10-15', [(3, 8), (10, 16)], draft=1)
def testMultipleRangesBigFile(self):
self.uploadBigFile()
self.expectMultipleRanges('3-700,10-15,-10000',
......
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