support more range specifiers in ranged gets

This commit is contained in:
Konstantinos Koukopoulos 2015-02-10 17:55:44 +02:00
parent dbf1e64d44
commit 9efd12c43c
2 changed files with 7 additions and 2 deletions

View File

@ -237,7 +237,10 @@ class ResponseObject(_TemplateEnvironmentMixin):
begin = 0
end = None
if 'range' in request.headers:
begin, end = map(int, request.headers.get('range').split('-'))
_, rspec = request.headers.get('range').split('=')
if ',' in rspec:
raise NotImplementedError("Multiple range specifiers not supported")
begin, end = map(lambda i: int(i) if i else None, rspec.split('-'))
if isinstance(response, six.string_types):
return 200, headers, response[begin:end]

View File

@ -701,4 +701,6 @@ def test_ranged_get():
key = Key(bucket)
key.key = 'bigkey'
key.set_contents_from_string('0' * 50 + '1' * 50)
key.get_contents_as_string(headers={'Range': '45-55'}).should.equal('0' * 5 + '1' * 5)
key.get_contents_as_string(headers={'Range': 'bytes=45-55'}).should.equal(b'0' * 5 + b'1' * 5)
key.get_contents_as_string(headers={'Range': 'bytes=45-'}).should.equal(b'0' * 5 + b'1' * 50)
key.get_contents_as_string(headers={'Range': 'bytes=-55'}).should.equal(b'0' * 50 + b'1' * 5)