1
- import aiohttp
2
1
import asyncio
3
2
4
- import aiohttp .http_exceptions
5
3
from botocore .endpoint import EndpointCreator , Endpoint , DEFAULT_TIMEOUT , \
6
4
MAX_POOL_CONNECTIONS , logger , history_recorder , create_request_object , \
7
- is_valid_ipv6_endpoint_url , is_valid_endpoint_url , handle_checksum_body
8
- from botocore .exceptions import ConnectionClosedError
5
+ is_valid_ipv6_endpoint_url , is_valid_endpoint_url , HTTPClientError
9
6
from botocore .hooks import first_non_none_response
10
7
from urllib3 .response import HTTPHeaderDict
11
8
12
9
from aiobotocore .httpsession import AIOHTTPSession
13
10
from aiobotocore .response import StreamingBody
14
- from aiobotocore ._endpoint_helpers import ClientResponseProxy # noqa: F401, E501 lgtm [py/unused-import]
11
+ from aiobotocore .httpchecksum import handle_checksum_body
15
12
16
13
17
14
async def convert_to_response_dict (http_response , operation_model ):
@@ -37,21 +34,21 @@ async def convert_to_response_dict(http_response, operation_model):
37
34
# aiohttp's CIMultiDict camel cases the headers :(
38
35
'headers' : HTTPHeaderDict (
39
36
{k .decode ('utf-8' ).lower (): v .decode ('utf-8' )
40
- for k , v in http_response .raw_headers }),
37
+ for k , v in http_response .raw . raw_headers }),
41
38
'status_code' : http_response .status_code ,
42
39
'context' : {
43
40
'operation_name' : operation_model .name ,
44
41
}
45
42
}
46
43
if response_dict ['status_code' ] >= 300 :
47
- response_dict ['body' ] = await http_response .read ()
44
+ response_dict ['body' ] = await http_response .content
48
45
elif operation_model .has_event_stream_output :
49
46
response_dict ['body' ] = http_response .raw
50
47
elif operation_model .has_streaming_output :
51
48
length = response_dict ['headers' ].get ('content-length' )
52
49
response_dict ['body' ] = StreamingBody (http_response .raw , length )
53
50
else :
54
- response_dict ['body' ] = await http_response .read ()
51
+ response_dict ['body' ] = await http_response .content
55
52
return response_dict
56
53
57
54
@@ -150,13 +147,8 @@ async def _do_get_response(self, request, operation_model, context):
150
147
http_response = first_non_none_response (responses )
151
148
if http_response is None :
152
149
http_response = await self ._send (request )
153
- except aiohttp .ClientConnectionError as e :
154
- e .request = request # botocore expects the request property
150
+ except HTTPClientError as e :
155
151
return None , e
156
- except aiohttp .http_exceptions .BadStatusLine :
157
- better_exception = ConnectionClosedError (
158
- endpoint_url = request .url , request = request )
159
- return None , better_exception
160
152
except Exception as e :
161
153
logger .debug ("Exception received when sending HTTP request." ,
162
154
exc_info = True )
@@ -165,7 +157,7 @@ async def _do_get_response(self, request, operation_model, context):
165
157
# This returns the http_response and the parsed_data.
166
158
response_dict = await convert_to_response_dict (http_response ,
167
159
operation_model )
168
- handle_checksum_body (
160
+ await handle_checksum_body (
169
161
http_response , response_dict , context , operation_model ,
170
162
)
171
163
0 commit comments