Merge "Test for content-type params in multi-range response"
This commit is contained in:
commit
418f9b21ce
@ -637,6 +637,7 @@ class File(Base):
|
|||||||
|
|
||||||
self.chunked_write_in_progress = False
|
self.chunked_write_in_progress = False
|
||||||
self.content_type = None
|
self.content_type = None
|
||||||
|
self.content_range = None
|
||||||
self.size = None
|
self.size = None
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
|
|
||||||
@ -838,6 +839,8 @@ class File(Base):
|
|||||||
for hdr in self.conn.response.getheaders():
|
for hdr in self.conn.response.getheaders():
|
||||||
if hdr[0].lower() == 'content-type':
|
if hdr[0].lower() == 'content-type':
|
||||||
self.content_type = hdr[1]
|
self.content_type = hdr[1]
|
||||||
|
if hdr[0].lower() == 'content-range':
|
||||||
|
self.content_range = hdr[1]
|
||||||
|
|
||||||
if hasattr(buffer, 'write'):
|
if hasattr(buffer, 'write'):
|
||||||
scratch = self.conn.response.read(8192)
|
scratch = self.conn.response.read(8192)
|
||||||
|
@ -1656,7 +1656,8 @@ class TestFile(Base):
|
|||||||
subrange_size = range_size / 10
|
subrange_size = range_size / 10
|
||||||
file_item = self.env.container.file(Utils.create_name())
|
file_item = self.env.container.file(Utils.create_name())
|
||||||
data = file_item.write_random(
|
data = file_item.write_random(
|
||||||
file_length, hdrs={"Content-Type": "lovecraft/rugose"})
|
file_length, hdrs={"Content-Type":
|
||||||
|
"lovecraft/rugose; squamous=true"})
|
||||||
|
|
||||||
for i in range(0, file_length, range_size):
|
for i in range(0, file_length, range_size):
|
||||||
range_string = 'bytes=%d-%d,%d-%d,%d-%d' % (
|
range_string = 'bytes=%d-%d,%d-%d,%d-%d' % (
|
||||||
@ -1666,7 +1667,10 @@ class TestFile(Base):
|
|||||||
hdrs = {'Range': range_string}
|
hdrs = {'Range': range_string}
|
||||||
|
|
||||||
fetched = file_item.read(hdrs=hdrs)
|
fetched = file_item.read(hdrs=hdrs)
|
||||||
|
self.assert_status(206)
|
||||||
content_type = file_item.content_type
|
content_type = file_item.content_type
|
||||||
|
self.assertTrue(content_type.startswith("multipart/byteranges"))
|
||||||
|
self.assertIsNone(file_item.content_range)
|
||||||
|
|
||||||
# email.parser.FeedParser wants a message with headers on the
|
# email.parser.FeedParser wants a message with headers on the
|
||||||
# front, then two CRLFs, and then a body (like emails have but
|
# front, then two CRLFs, and then a body (like emails have but
|
||||||
@ -1682,7 +1686,8 @@ class TestFile(Base):
|
|||||||
byteranges = root_message.get_payload()
|
byteranges = root_message.get_payload()
|
||||||
self.assertEqual(len(byteranges), 3)
|
self.assertEqual(len(byteranges), 3)
|
||||||
|
|
||||||
self.assertEqual(byteranges[0]['Content-Type'], "lovecraft/rugose")
|
self.assertEqual(byteranges[0]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[0]['Content-Range'],
|
byteranges[0]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (i, i + subrange_size - 1, file_length))
|
"bytes %d-%d/%d" % (i, i + subrange_size - 1, file_length))
|
||||||
@ -1690,7 +1695,8 @@ class TestFile(Base):
|
|||||||
byteranges[0].get_payload(),
|
byteranges[0].get_payload(),
|
||||||
data[i:(i + subrange_size)])
|
data[i:(i + subrange_size)])
|
||||||
|
|
||||||
self.assertEqual(byteranges[1]['Content-Type'], "lovecraft/rugose")
|
self.assertEqual(byteranges[1]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[1]['Content-Range'],
|
byteranges[1]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (i + 2 * subrange_size,
|
"bytes %d-%d/%d" % (i + 2 * subrange_size,
|
||||||
@ -1699,7 +1705,8 @@ class TestFile(Base):
|
|||||||
byteranges[1].get_payload(),
|
byteranges[1].get_payload(),
|
||||||
data[(i + 2 * subrange_size):(i + 3 * subrange_size)])
|
data[(i + 2 * subrange_size):(i + 3 * subrange_size)])
|
||||||
|
|
||||||
self.assertEqual(byteranges[2]['Content-Type'], "lovecraft/rugose")
|
self.assertEqual(byteranges[2]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[2]['Content-Range'],
|
byteranges[2]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (i + 4 * subrange_size,
|
"bytes %d-%d/%d" % (i + 4 * subrange_size,
|
||||||
@ -1717,7 +1724,10 @@ class TestFile(Base):
|
|||||||
file_length, file_length + subrange_size - 1)
|
file_length, file_length + subrange_size - 1)
|
||||||
hdrs = {'Range': range_string}
|
hdrs = {'Range': range_string}
|
||||||
fetched = file_item.read(hdrs=hdrs)
|
fetched = file_item.read(hdrs=hdrs)
|
||||||
|
self.assert_status(206)
|
||||||
content_type = file_item.content_type
|
content_type = file_item.content_type
|
||||||
|
self.assertTrue(content_type.startswith("multipart/byteranges"))
|
||||||
|
self.assertIsNone(file_item.content_range)
|
||||||
|
|
||||||
parser = email.parser.FeedParser()
|
parser = email.parser.FeedParser()
|
||||||
parser.feed("Content-Type: %s\r\n\r\n" % content_type)
|
parser.feed("Content-Type: %s\r\n\r\n" % content_type)
|
||||||
@ -1728,13 +1738,15 @@ class TestFile(Base):
|
|||||||
byteranges = root_message.get_payload()
|
byteranges = root_message.get_payload()
|
||||||
self.assertEqual(len(byteranges), 2)
|
self.assertEqual(len(byteranges), 2)
|
||||||
|
|
||||||
self.assertEqual(byteranges[0]['Content-Type'], 'lovecraft/rugose')
|
self.assertEqual(byteranges[0]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[0]['Content-Range'],
|
byteranges[0]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
||||||
self.assertEqual(byteranges[0].get_payload(), data[:subrange_size])
|
self.assertEqual(byteranges[0].get_payload(), data[:subrange_size])
|
||||||
|
|
||||||
self.assertEqual(byteranges[1]['Content-Type'], 'lovecraft/rugose')
|
self.assertEqual(byteranges[1]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[1]['Content-Range'],
|
byteranges[1]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (2 * subrange_size, 3 * subrange_size - 1,
|
"bytes %d-%d/%d" % (2 * subrange_size, 3 * subrange_size - 1,
|
||||||
@ -1751,8 +1763,10 @@ class TestFile(Base):
|
|||||||
file_length, file_length + subrange_size - 1)
|
file_length, file_length + subrange_size - 1)
|
||||||
hdrs = {'Range': range_string}
|
hdrs = {'Range': range_string}
|
||||||
fetched = file_item.read(hdrs=hdrs)
|
fetched = file_item.read(hdrs=hdrs)
|
||||||
|
self.assert_status(206)
|
||||||
content_type = file_item.content_type
|
content_type = file_item.content_type
|
||||||
if content_type.startswith("multipart/byteranges"):
|
if content_type.startswith("multipart/byteranges"):
|
||||||
|
self.assertIsNone(file_item.content_range)
|
||||||
parser = email.parser.FeedParser()
|
parser = email.parser.FeedParser()
|
||||||
parser.feed("Content-Type: %s\r\n\r\n" % content_type)
|
parser.feed("Content-Type: %s\r\n\r\n" % content_type)
|
||||||
parser.feed(fetched)
|
parser.feed(fetched)
|
||||||
@ -1762,17 +1776,17 @@ class TestFile(Base):
|
|||||||
byteranges = root_message.get_payload()
|
byteranges = root_message.get_payload()
|
||||||
self.assertEqual(len(byteranges), 1)
|
self.assertEqual(len(byteranges), 1)
|
||||||
|
|
||||||
self.assertEqual(byteranges[0]['Content-Type'], 'lovecraft/rugose')
|
self.assertEqual(byteranges[0]['Content-Type'],
|
||||||
|
"lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
byteranges[0]['Content-Range'],
|
byteranges[0]['Content-Range'],
|
||||||
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
||||||
self.assertEqual(byteranges[0].get_payload(), data[:subrange_size])
|
self.assertEqual(byteranges[0].get_payload(), data[:subrange_size])
|
||||||
else:
|
else:
|
||||||
headers = dict((h.title(), v)
|
|
||||||
for h, v in self.env.conn.response.getheaders())
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
headers['Content-Range'],
|
file_item.content_range,
|
||||||
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
"bytes %d-%d/%d" % (0, subrange_size - 1, file_length))
|
||||||
|
self.assertEqual(content_type, "lovecraft/rugose; squamous=true")
|
||||||
self.assertEqual(fetched, data[:subrange_size])
|
self.assertEqual(fetched, data[:subrange_size])
|
||||||
|
|
||||||
# No byterange is satisfiable, so we get a 416 response.
|
# No byterange is satisfiable, so we get a 416 response.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user