Merge "Include accept-ranges header in s3api response"

This commit is contained in:
Zuul 2023-10-14 00:40:37 +00:00 committed by Gerrit Code Review
commit 9191a32e2e
3 changed files with 34 additions and 3 deletions

View File

@ -64,7 +64,7 @@ def translate_swift_to_s3(key, val):
if _key.startswith('x-object-meta-'): if _key.startswith('x-object-meta-'):
return translate_meta_key(_key), val return translate_meta_key(_key), val
elif _key in ('content-length', 'content-type', elif _key in ('accept-ranges', 'content-length', 'content-type',
'content-range', 'content-encoding', 'content-range', 'content-encoding',
'content-disposition', 'content-language', 'content-disposition', 'content-language',
'etag', 'last-modified', 'x-robots-tag', 'etag', 'last-modified', 'x-robots-tag',

View File

@ -133,6 +133,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertTrue(headers['last-modified'] is not None) self.assertTrue(headers['last-modified'] is not None)
self.assertTrue(headers['content-type'] is not None) self.assertTrue(headers['content-type'] is not None)
self.assertEqual(headers['content-length'], str(len(content))) self.assertEqual(headers['content-length'], str(len(content)))
self.assertEqual(headers['accept-ranges'], 'bytes')
# HEAD Object # HEAD Object
status, headers, body = \ status, headers, body = \
@ -143,6 +144,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertTrue(headers['last-modified'] is not None) self.assertTrue(headers['last-modified'] is not None)
self.assertTrue('content-type' in headers) self.assertTrue('content-type' in headers)
self.assertEqual(headers['content-length'], str(len(content))) self.assertEqual(headers['content-length'], str(len(content)))
self.assertEqual(headers['accept-ranges'], 'bytes')
# DELETE Object # DELETE Object
status, headers, body = \ status, headers, body = \
@ -671,6 +673,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertEqual(headers['content-type'], 'text/plain') self.assertEqual(headers['content-type'], 'text/plain')
self.assertTrue('accept-ranges' in headers)
def test_get_object_response_content_language(self): def test_get_object_response_content_language(self):
obj = 'object' obj = 'object'
@ -682,6 +685,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertEqual(headers['content-language'], 'en') self.assertEqual(headers['content-language'], 'en')
self.assertTrue('accept-ranges' in headers)
def test_get_object_response_cache_control(self): def test_get_object_response_cache_control(self):
obj = 'object' obj = 'object'
@ -692,6 +696,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, query=query) self.conn.make_request('GET', self.bucket, obj, query=query)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['cache-control'], 'private') self.assertEqual(headers['cache-control'], 'private')
def test_get_object_response_content_disposition(self): def test_get_object_response_content_disposition(self):
@ -704,6 +709,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertEqual(headers['content-disposition'], 'inline') self.assertEqual(headers['content-disposition'], 'inline')
self.assertTrue('accept-ranges' in headers)
def test_get_object_response_content_encoding(self): def test_get_object_response_content_encoding(self):
obj = 'object' obj = 'object'
@ -715,6 +721,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertEqual(headers['content-encoding'], 'gzip') self.assertEqual(headers['content-encoding'], 'gzip')
self.assertTrue('accept-ranges' in headers)
def test_get_object_range(self): def test_get_object_range(self):
obj = 'object' obj = 'object'
@ -730,6 +737,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 206) self.assertEqual(status, 206)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('content-length' in headers) self.assertTrue('content-length' in headers)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertTrue('x-amz-meta-test' in headers) self.assertTrue('x-amz-meta-test' in headers)
self.assertEqual('swift', headers['x-amz-meta-test']) self.assertEqual('swift', headers['x-amz-meta-test'])
@ -742,6 +750,7 @@ class TestS3ApiObject(S3ApiBase):
self.assertEqual(status, 206) self.assertEqual(status, 206)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('content-length' in headers) self.assertTrue('content-length' in headers)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertTrue('x-amz-meta-test' in headers) self.assertTrue('x-amz-meta-test' in headers)
self.assertEqual('swift', headers['x-amz-meta-test']) self.assertEqual('swift', headers['x-amz-meta-test'])
@ -752,6 +761,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 206) self.assertEqual(status, 206)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
self.assertTrue('content-length' in headers) self.assertTrue('content-length' in headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertTrue('x-amz-meta-test' in headers) self.assertTrue('x-amz-meta-test' in headers)
@ -765,6 +775,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 206) self.assertEqual(status, 206)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
self.assertIn('content-length', headers) self.assertIn('content-length', headers)
self.assertIn('content-type', headers) # sanity self.assertIn('content-type', headers) # sanity
@ -816,6 +827,7 @@ class TestS3ApiObject(S3ApiBase):
status, headers, body = \ status, headers, body = \
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertTrue('accept-ranges' in headers)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
def test_get_object_if_unmodified_since(self): def test_get_object_if_unmodified_since(self):
@ -831,7 +843,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
# check we can use the last modified time from the listing... # check we can use the last modified time from the listing...
status, headers, body = \ status, headers, body = \
self.conn.make_request('GET', self.bucket) self.conn.make_request('GET', self.bucket)
@ -847,11 +859,13 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
headers = {'If-Modified-Since': header_datetime} headers = {'If-Modified-Since': header_datetime}
status, headers, body = \ status, headers, body = \
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 304) self.assertEqual(status, 304)
self.assertTrue('accept-ranges' in headers)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
def test_get_object_if_match(self): def test_get_object_if_match(self):
@ -867,6 +881,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
def test_get_object_if_none_match(self): def test_get_object_if_none_match(self):
obj = 'object' obj = 'object'
@ -876,6 +891,7 @@ class TestS3ApiObject(S3ApiBase):
status, headers, body = \ status, headers, body = \
self.conn.make_request('GET', self.bucket, obj, headers=headers) self.conn.make_request('GET', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertTrue('accept-ranges' in headers)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
def test_head_object_range(self): def test_head_object_range(self):
@ -888,18 +904,21 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
headers = {'Range': 'bytes=5-'} headers = {'Range': 'bytes=5-'}
status, headers, body = \ status, headers, body = \
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
headers = {'Range': 'bytes=-5'} headers = {'Range': 'bytes=-5'}
status, headers, body = \ status, headers, body = \
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(headers['content-length'], '5') self.assertEqual(headers['content-length'], '5')
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
def test_head_object_if_modified_since(self): def test_head_object_if_modified_since(self):
obj = 'object' obj = 'object'
@ -914,6 +933,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
def test_head_object_if_unmodified_since(self): def test_head_object_if_unmodified_since(self):
obj = 'object' obj = 'object'
@ -928,6 +948,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
def test_head_object_if_match(self): def test_head_object_if_match(self):
obj = 'object' obj = 'object'
@ -942,6 +963,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
def test_head_object_if_none_match(self): def test_head_object_if_none_match(self):
obj = 'object' obj = 'object'
@ -952,6 +974,7 @@ class TestS3ApiObject(S3ApiBase):
self.conn.make_request('HEAD', self.bucket, obj, headers=headers) self.conn.make_request('HEAD', self.bucket, obj, headers=headers)
self.assertEqual(status, 200) self.assertEqual(status, 200)
self.assertCommonResponseHeaders(headers) self.assertCommonResponseHeaders(headers)
self.assertTrue('accept-ranges' in headers)
class TestS3ApiObjectSigV4(TestS3ApiObject, SigV4Mixin): class TestS3ApiObjectSigV4(TestS3ApiObject, SigV4Mixin):

View File

@ -53,6 +53,7 @@ class TestS3ApiObj(S3ApiTestCase):
self.response_headers = {'Content-Type': 'text/html', self.response_headers = {'Content-Type': 'text/html',
'Content-Length': len(self.object_body), 'Content-Length': len(self.object_body),
'Accept-Ranges': 'bytes',
'Content-Disposition': 'inline', 'Content-Disposition': 'inline',
'Content-Language': 'en', 'Content-Language': 'en',
'x-object-meta-test': 'swift', 'x-object-meta-test': 'swift',
@ -89,7 +90,8 @@ class TestS3ApiObj(S3ApiTestCase):
for key, val in self.response_headers.items(): for key, val in self.response_headers.items():
if key in ('Content-Length', 'Content-Type', 'content-encoding', if key in ('Content-Length', 'Content-Type', 'content-encoding',
'last-modified', 'cache-control', 'Content-Disposition', 'last-modified', 'cache-control', 'Content-Disposition',
'Content-Language', 'expires', 'x-robots-tag'): 'Content-Language', 'expires', 'x-robots-tag',
'Accept-Ranges'):
self.assertIn(key, headers) self.assertIn(key, headers)
self.assertEqual(headers[key], str(val)) self.assertEqual(headers[key], str(val))
@ -407,6 +409,8 @@ class TestS3ApiObj(S3ApiTestCase):
self.assertTrue('cache-control' in headers) self.assertTrue('cache-control' in headers)
self.assertEqual(headers['cache-control'], 'no-cache') self.assertEqual(headers['cache-control'], 'no-cache')
self.assertTrue('content-disposition' in headers) self.assertTrue('content-disposition' in headers)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['accept-ranges'], 'bytes')
self.assertEqual(headers['content-disposition'], self.assertEqual(headers['content-disposition'],
'attachment') 'attachment')
self.assertTrue('content-encoding' in headers) self.assertTrue('content-encoding' in headers)
@ -435,6 +439,8 @@ class TestS3ApiObj(S3ApiTestCase):
status, headers, body = self.call_s3api(req) status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200', body) self.assertEqual(status.split()[0], '200', body)
self.assertEqual(body, self.object_body) self.assertEqual(body, self.object_body)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['accept-ranges'], 'bytes')
@s3acl @s3acl
def test_object_GET_version_id(self): def test_object_GET_version_id(self):
@ -455,6 +461,8 @@ class TestS3ApiObj(S3ApiTestCase):
status, headers, body = self.call_s3api(req) status, headers, body = self.call_s3api(req)
self.assertEqual(status.split()[0], '200', body) self.assertEqual(status.split()[0], '200', body)
self.assertEqual(body, self.object_body) self.assertEqual(body, self.object_body)
self.assertTrue('accept-ranges' in headers)
self.assertEqual(headers['accept-ranges'], 'bytes')
# GET version in archive # GET version in archive
headers = self.response_headers.copy() headers = self.response_headers.copy()