d.addCallback(_got)
return d
+ def test_GET_FILEURL_partial_range(self):
+ headers = {"range": "bytes=5-"}
+ length = len(self.BAR_CONTENTS)
+ d = self.GET(self.public_url + "/foo/bar.txt", headers=headers,
+ return_response=True)
+ def _got((res, status, headers)):
+ self.failUnlessEqual(int(status), 206)
+ self.failUnless(headers.has_key("content-range"))
+ self.failUnlessEqual(headers["content-range"][0],
+ "bytes 5-%d/%d" % (length-1, length))
+ self.failUnlessEqual(res, self.BAR_CONTENTS[5:])
+ d.addCallback(_got)
+ return d
+
def test_HEAD_FILEURL_range(self):
headers = {"range": "bytes=1-10"}
d = self.HEAD(self.public_url + "/foo/bar.txt", headers=headers,
d.addCallback(_got)
return d
+ def test_HEAD_FILEURL_partial_range(self):
+ headers = {"range": "bytes=5-"}
+ length = len(self.BAR_CONTENTS)
+ d = self.HEAD(self.public_url + "/foo/bar.txt", headers=headers,
+ return_response=True)
+ def _got((res, status, headers)):
+ self.failUnlessEqual(int(status), 206)
+ self.failUnless(headers.has_key("content-range"))
+ self.failUnlessEqual(headers["content-range"][0],
+ "bytes 5-%d/%d" % (length-1, length))
+ d.addCallback(_got)
+ return d
+
def test_GET_FILEURL_range_bad(self):
headers = {"range": "BOGUS=fizbop-quarnak"}
d = self.shouldFail2(error.Error, "test_GET_FILEURL_range_bad",
start, end = bytesrange[1].split('-')
if start:
offset = int(start)
- if end:
+ if not end:
+ # RFC 2616 says:
+ #
+ # "If the last-byte-pos value is absent, or if the value is
+ # greater than or equal to the current length of the
+ # entity-body, last-byte-pos is taken to be equal to one less
+ # than the current length of the entity- body in bytes."
+ end = filesize - 1
size = int(end) - offset + 1
req.setResponseCode(http.PARTIAL_CONTENT)
req.setHeader('content-range',"bytes %s-%s/%s" %