Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert botocore.awsrequest.AWSResponse to dict #759

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions aiobotocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from botocore.exceptions import ConnectionClosedError
from botocore.hooks import first_non_none_response
from botocore.utils import is_valid_endpoint_url
from botocore.utils import lowercase_dict
from multidict import MultiDict
from urllib.parse import urlparse
from urllib3.response import HTTPHeaderDict
Expand All @@ -23,7 +24,7 @@ async def convert_to_response_dict(http_response, operation_model):
This converts the requests library's HTTP response object to
a dictionary.

:type http_response: botocore.vendored.requests.model.Response
:type http_response: botocore.awsrequest.AWSResponse
:param http_response: The HTTP response from an AWS service request.

:rtype: dict
Expand All @@ -34,27 +35,21 @@ async def convert_to_response_dict(http_response, operation_model):

"""
response_dict = {
# botocore converts keys to str, so make sure that they are in
# the expected case. See detailed discussion here:
# https://github.com/aio-libs/aiobotocore/pull/116
# aiohttp's CIMultiDict camel cases the headers :(
'headers': HTTPHeaderDict(
{k.decode('utf-8').lower(): v.decode('utf-8')
for k, v in http_response.raw_headers}),
'headers': HTTPHeaderDict(lowercase_dict(http_response.headers)),
'status_code': http_response.status_code,
'context': {
'operation_name': operation_model.name,
}
}
if response_dict['status_code'] >= 300:
response_dict['body'] = await http_response.read()
response_dict['body'] = http_response.content
elif operation_model.has_event_stream_output:
response_dict['body'] = http_response.raw
elif operation_model.has_streaming_output:
length = response_dict['headers'].get('content-length')
response_dict['body'] = StreamingBody(http_response.raw, length)
else:
response_dict['body'] = await http_response.read()
response_dict['body'] = http_response.content
return response_dict


Expand Down