adding Accept-Ranges: bytes header to HEAD and GET requests.
This commit is contained in:
parent
8137aa6ed3
commit
22f88ce4af
@ -645,6 +645,7 @@ class Controller(object):
|
||||
raise
|
||||
res.app_iter = file_iter()
|
||||
update_headers(res, source.getheaders())
|
||||
update_headers(res, {'accept-ranges':'bytes'})
|
||||
res.status = source.status
|
||||
res.content_length = source.getheader('Content-Length')
|
||||
if source.getheader('Content-Type'):
|
||||
@ -654,6 +655,7 @@ class Controller(object):
|
||||
elif 200 <= source.status <= 399:
|
||||
res = status_map[source.status](request=req)
|
||||
update_headers(res, source.getheaders())
|
||||
update_headers(res, {'accept-ranges':'bytes'})
|
||||
if req.method == 'HEAD':
|
||||
res.content_length = source.getheader('Content-Length')
|
||||
if source.getheader('Content-Type'):
|
||||
@ -828,6 +830,7 @@ class ObjectController(Controller):
|
||||
resp)
|
||||
resp.content_length = content_length
|
||||
resp.last_modified = last_modified
|
||||
resp.headers['accept-ranges'] = 'bytes'
|
||||
|
||||
return resp
|
||||
|
||||
|
@ -976,6 +976,9 @@ class TestObjectController(unittest.TestCase):
|
||||
if expected < 400:
|
||||
self.assert_('x-works' in res.headers)
|
||||
self.assertEquals(res.headers['x-works'], 'yes')
|
||||
self.assert_('accept-ranges' in res.headers)
|
||||
self.assertEquals(res.headers['accept-ranges'], 'bytes')
|
||||
|
||||
test_status_map((200, 404, 404), 200)
|
||||
test_status_map((200, 500, 404), 200)
|
||||
test_status_map((304, 500, 404), 304)
|
||||
@ -2488,6 +2491,28 @@ class TestObjectController(unittest.TestCase):
|
||||
finally:
|
||||
self.app.object_chunk_size = orig_object_chunk_size
|
||||
|
||||
def test_response_get_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
||||
self.app.update_request(req)
|
||||
controller = proxy_server.ObjectController(self.app, 'account',
|
||||
'container', 'object')
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, 200)
|
||||
resp = controller.GET(req)
|
||||
self.assert_('accept-ranges' in resp.headers)
|
||||
self.assertEquals(resp.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_response_head_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'GET'})
|
||||
self.app.update_request(req)
|
||||
controller = proxy_server.ObjectController(self.app, 'account',
|
||||
'container', 'object')
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, 200)
|
||||
resp = controller.HEAD(req)
|
||||
self.assert_('accept-ranges' in resp.headers)
|
||||
self.assertEquals(resp.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_GET_calls_authorize(self):
|
||||
called = [False]
|
||||
|
||||
@ -2827,6 +2852,28 @@ class TestContainerController(unittest.TestCase):
|
||||
finally:
|
||||
self.app.object_chunk_size = orig_object_chunk_size
|
||||
|
||||
def test_response_get_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, body='{}')
|
||||
controller = proxy_server.ContainerController(self.app, 'account',
|
||||
'container')
|
||||
req = Request.blank('/a/c?format=json')
|
||||
self.app.update_request(req)
|
||||
res = controller.GET(req)
|
||||
self.assert_('accept-ranges' in res.headers)
|
||||
self.assertEqual(res.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_response_head_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, body='{}')
|
||||
controller = proxy_server.ContainerController(self.app, 'account',
|
||||
'container')
|
||||
req = Request.blank('/a/c?format=json')
|
||||
self.app.update_request(req)
|
||||
res = controller.HEAD(req)
|
||||
self.assert_('accept-ranges' in res.headers)
|
||||
self.assertEqual(res.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_PUT_metadata(self):
|
||||
self.metadata_helper('PUT')
|
||||
|
||||
@ -3133,6 +3180,27 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assert_(hasattr(res, 'bytes_transferred'))
|
||||
self.assertEquals(res.bytes_transferred, 2)
|
||||
|
||||
def test_response_get_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, body='{}')
|
||||
controller = proxy_server.AccountController(self.app, 'account')
|
||||
req = Request.blank('/a?format=json')
|
||||
self.app.update_request(req)
|
||||
res = controller.GET(req)
|
||||
self.assert_('accept-ranges' in res.headers)
|
||||
self.assertEqual(res.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_response_head_accept_ranges_header(self):
|
||||
with save_globals():
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, body='{}')
|
||||
controller = proxy_server.AccountController(self.app, 'account')
|
||||
req = Request.blank('/a?format=json')
|
||||
self.app.update_request(req)
|
||||
res = controller.HEAD(req)
|
||||
res.body
|
||||
self.assert_('accept-ranges' in res.headers)
|
||||
self.assertEqual(res.headers['accept-ranges'], 'bytes')
|
||||
|
||||
def test_response_client_disconnect_attr(self):
|
||||
with save_globals():
|
||||
proxy_server.http_connect = fake_http_connect(200, 200, body='{}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user