Skip to content

Commit

Permalink
Add support for parsing S3 metadata types
Browse files Browse the repository at this point in the history
A special case is required to parsed rest-xml, map types
with a location of header.  The only place this is used is for
S3 metadata types.
  • Loading branch information
jamesls committed Apr 21, 2014
1 parent 865fcb2 commit 0f50a53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 15 additions & 1 deletion botocore/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,23 @@ def merge_header_values(self, headers):
location = member.get('location')
if location == 'header':
location_name = member.get('location_name')
if location_name in headers:
if member['type'] == 'map':
self._merge_map_header_values(headers, location_name,
member_name, member)
elif location_name in headers:
self.value[member_name] = headers[location_name]

def _merge_map_header_values(self, headers, location_name,
member_name, member):
final_map_value = {}
for header_name in headers:
if header_name.startswith(location_name):
header_value = headers[header_name]
actual_name = header_name[len(location_name):]
final_map_value[actual_name] = header_value
if final_map_value:
self.value[member_name] = final_map_value


class JSONResponse(Response):

Expand Down
11 changes: 8 additions & 3 deletions tests/unit/response_parsing/test_response_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def test_head_object(self):
'Content-Type': 'binary/octet-stream',
'accept-ranges': 'bytes',
'Last-Modified': 'Tue, 20 Aug 2013 18:33:25 GMT',
'x-amz-server-side-encryption': 'AES256'
'x-amz-server-side-encryption': 'AES256',
'x-amz-meta-mykey1': 'value1',
'x-amz-meta-mykey2': 'value2',
})
http_response.content = ''
http_response.request.method = 'HEAD'
Expand All @@ -185,8 +187,11 @@ def test_head_object(self):
"LastModified": "Tue, 20 Aug 2013 18:33:25 GMT",
"ContentLength": "265",
"ETag": '"40d06eb6194712ac1c915783004ef730"',
"ServerSideEncryption": "AES256"
}
"ServerSideEncryption": "AES256",
"Metadata": {
'mykey1': 'value1',
'mykey2': 'value2',
}}
response_data = get_response(self.session, put_object,
http_response)[1]
self.assertEqual(response_data, expected)
Expand Down

0 comments on commit 0f50a53

Please sign in to comment.