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

Add support for httpx as backend #1085

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ secret accessible via environment variables:
::

$ pip install pip-tools
$ pip-compile requirements-dev.txt
$ pip-compile requirements-dev.in
$ pip-sync requirements-dev.txt
$ export AWS_ACCESS_KEY_ID=xxx
$ export AWS_SECRET_ACCESS_KEY=xxx
$ export AWS_DEFAULT_REGION=xxx # e.g. us-west-2

Execute tests suite:

Expand Down
26 changes: 13 additions & 13 deletions aiobotocore/_endpoint_helpers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import asyncio
# import asyncio

import aiohttp.http_exceptions
# import aiohttp.http_exceptions
import botocore.retryhandler
import wrapt

# Monkey patching: We need to insert the aiohttp exception equivalents
# The only other way to do this would be to have another config file :(
_aiohttp_retryable_exceptions = [
aiohttp.ClientConnectionError,
aiohttp.ClientPayloadError,
aiohttp.ServerDisconnectedError,
aiohttp.http_exceptions.HttpProcessingError,
asyncio.TimeoutError,
]

botocore.retryhandler.EXCEPTION_MAP['GENERAL_CONNECTION_ERROR'].extend(
_aiohttp_retryable_exceptions
)
# _aiohttp_retryable_exceptions = [
# aiohttp.ClientConnectionError,
# aiohttp.ClientPayloadError,
# aiohttp.ServerDisconnectedError,
# aiohttp.http_exceptions.HttpProcessingError,
# asyncio.TimeoutError,
# ]
#
# botocore.retryhandler.EXCEPTION_MAP['GENERAL_CONNECTION_ERROR'].extend(
# _aiohttp_retryable_exceptions
# )


def _text(s, encoding='utf-8', errors='strict'):
Expand Down
6 changes: 5 additions & 1 deletion aiobotocore/awsrequest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import botocore.utils
import httpx
from botocore.awsrequest import AWSResponse


Expand All @@ -10,7 +11,10 @@ async def _content_prop(self):

if self._content is None:
# NOTE: this will cache the data in self.raw
self._content = await self.raw.read() or b''
if isinstance(self.raw, httpx.Response):
self._content = await self.raw.aread() or b''
jakkdl marked this conversation as resolved.
Show resolved Hide resolved
else:
self._content = await self.raw.read() or b''

return self._content

Expand Down
26 changes: 17 additions & 9 deletions aiobotocore/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
from typing import Any

import httpx
from botocore.endpoint import (
DEFAULT_TIMEOUT,
MAX_POOL_CONNECTIONS,
Expand All @@ -13,14 +15,19 @@
logger,
)
from botocore.hooks import first_non_none_response
from urllib3.response import HTTPHeaderDict
from requests.models import Response
from urllib3._collections import HTTPHeaderDict

from aiobotocore.httpchecksum import handle_checksum_body
from aiobotocore.httpsession import AIOHTTPSession
from aiobotocore.response import StreamingBody

# from botocore.awsrequest import AWSResponse

async def convert_to_response_dict(http_response, operation_model):

async def convert_to_response_dict(
http_response: Response, operation_model
) -> dict[str, Any]:
"""Convert an HTTP response object to a request dict.

This converts the requests library's HTTP response object to
Expand All @@ -36,15 +43,16 @@ async def convert_to_response_dict(http_response, operation_model):
* body (string or file-like object)

"""
response_dict = {
http_response.raw: httpx.Response
response_dict: dict[str, Any] = {
# 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.raw_headers
for k, v in http_response.raw.headers.raw
}
),
'status_code': http_response.status_code,
Expand Down Expand Up @@ -181,11 +189,11 @@ async def _do_get_response(self, request, operation_model, context):
http_response = await self._send(request)
except HTTPClientError as e:
return (None, e)
except Exception as e:
logger.debug(
"Exception received when sending HTTP request.", exc_info=True
)
return (None, e)
# except Exception as e:
# logger.debug(
# "Exception received when sending HTTP request.", exc_info=True
# )
# return (None, e)

# This returns the http_response and the parsed_data.
response_dict = await convert_to_response_dict(
Expand Down
Loading
Loading