Skip to content

Add support for httpx as backend #1085

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

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1eb6888
Replace aiohttp with httpx
jakkdl Feb 1, 2024
d10761c
WIP of full replacement of aiohttp with httpx
jakkdl Feb 9, 2024
3608872
mostly finished WIP of adding httpx support
jakkdl Feb 19, 2024
757819f
fix various test failures
jakkdl Feb 19, 2024
4327b58
fix more parametrization issues
jakkdl Feb 19, 2024
e123adc
fix typo current_http_stack -> current_http_backend
jakkdl Feb 19, 2024
d029aa4
Add pytest flag for specifying backend when running tests.
jakkdl Feb 20, 2024
8f6bd69
add initial retryable exceptions. _validate_connector_args will now g…
jakkdl Feb 20, 2024
bdc680c
yes
jakkdl Feb 20, 2024
48b7310
append coverage when running tests twice
jakkdl Mar 1, 2024
b19bc09
Merge branch 'master' into httpx
jakkdl Mar 1, 2024
3e38c06
fix normalization of key paths in urls, revert test
jakkdl Apr 3, 2024
3e29d0d
shuffle around code wrt retryable exception to be less confusing
jakkdl Apr 3, 2024
af293b0
Merge remote-tracking branch 'origin/master' into httpx
jakkdl Apr 3, 2024
4482464
Merge remote-tracking branch 'origin/master' into httpx
jakkdl Oct 19, 2024
9dff5be
fix failed merge
jakkdl Oct 19, 2024
746d6b1
ruamel/yaml release pulled, so minor commit to retrigger CI
jakkdl Oct 19, 2024
82f2bc8
pre-merge dir rename
jakkdl Feb 27, 2025
550b660
Merge remote-tracking branch 'origin/master' into httpx
jakkdl Feb 27, 2025
2fd7f29
first fixes after reviews
jakkdl Feb 28, 2025
d1c0d12
fix no-httpx ci run
jakkdl Feb 28, 2025
9462503
add HttpxStreamingBody to reduce test changes
jakkdl Feb 28, 2025
c5d4592
blah
jakkdl Feb 28, 2025
6b73fbb
Merge remote-tracking branch 'origin/master' into httpx
jakkdl Mar 3, 2025
4d4cf32
make no_httpx a separate matrix entry
jakkdl Mar 3, 2025
6daaa79
Merge branch 'master' into httpx
jakkdl Apr 7, 2025
03da7e7
Merge remote-tracking branch 'origin/master' into HEAD
jakkdl May 9, 2025
be976f1
error if unknown http backend
jakkdl May 14, 2025
ae6f1d0
Merge remote-tracking branch 'origin/master' into httpx
jakkdl May 14, 2025
041f7f1
add HttpxStreamingChecksumBody to fix tests. But there's probably a n…
jakkdl May 14, 2025
da5e9fa
fix test_output_compliance fails... as it uses global state 🙃
jakkdl May 14, 2025
e8ba517
stop using include in CI for conditional vars
jakkdl May 14, 2025
7f057b2
quote os value
jakkdl May 14, 2025
109a201
remove HttpxAWSResponse, replace with some logic in AioAWSResponse
jakkdl May 14, 2025
fd8e653
small fixes after review
jakkdl May 14, 2025
b977370
move skip_httpx to tests/conftest
jakkdl May 14, 2025
a4ee8c7
improve exception mapping & retryable exceptions
jakkdl May 15, 2025
e257182
convert iterables to async iterables instead of reading data in send
jakkdl May 19, 2025
81d120f
Merge remote-tracking branch 'origin/master' into httpx
jakkdl May 21, 2025
d7e5f4a
use wait_for_close instead of close in StreamingBody
jakkdl May 21, 2025
4149c4f
handle timeouts better, clean up comments
jakkdl May 21, 2025
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''
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