Fix response of Get Bucket when IsTruncated is true and delimiter is specified

When IsTruncated is true and delimiter is specified, add NextMarker tag to
response body.

Change-Id: Ifb2c71cf232b1a5b52518ce4d61131aac730ff74
This commit is contained in:
Naoto Nishizono
2014-12-25 11:09:06 +09:00
parent f5bd78c29b
commit c03a1b5b4b
2 changed files with 42 additions and 7 deletions

View File

@@ -76,6 +76,20 @@ class BucketController(Controller):
SubElement(elem, 'Name').text = req.container_name
SubElement(elem, 'Prefix').text = req.params.get('prefix')
SubElement(elem, 'Marker').text = req.params.get('marker')
# in order to judge that truncated is valid, check whether
# max_keys + 1 th element exists in swift.
is_truncated = max_keys > 0 and len(objects) > max_keys
objects = objects[:max_keys]
if is_truncated and 'delimiter' in req.params:
if 'name' in objects[-1]:
SubElement(elem, 'NextMarker').text = \
objects[-1]['name']
if 'subdir' in objects[-1]:
SubElement(elem, 'NextMarker').text = \
objects[-1]['subdir']
SubElement(elem, 'MaxKeys').text = str(max_keys)
if 'delimiter' in req.params:
@@ -84,13 +98,10 @@ class BucketController(Controller):
if encoding_type is not None:
SubElement(elem, 'EncodingType').text = encoding_type
if max_keys > 0 and len(objects) == max_keys + 1:
is_truncated = 'true'
else:
is_truncated = 'false'
SubElement(elem, 'IsTruncated').text = is_truncated
SubElement(elem, 'IsTruncated').text = \
'true' if is_truncated else 'false'
for o in objects[:max_keys]:
for o in objects:
if 'subdir' not in o:
contents = SubElement(elem, 'Contents')
SubElement(contents, 'Key').text = o['name']
@@ -103,7 +114,7 @@ class BucketController(Controller):
SubElement(owner, 'DisplayName').text = req.user_id
SubElement(contents, 'StorageClass').text = 'STANDARD'
for o in objects[:max_keys]:
for o in objects:
if 'subdir' in o:
common_prefixes = SubElement(elem, 'CommonPrefixes')
SubElement(common_prefixes, 'Prefix').text = o['subdir']