-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The problem
Currently Lapidary supports only httpx and it's rather tightly integrated with it. The tight integration makes it hard to replace the underlying http client (#77) and impossible for users to introduce any customizations.
Solution
HTTP client adapter will be a component that conceptually sits between data serializer and http client, the whole being wrapped and managed by the ClientBase instance.
Lapidary really just converts python data into HTTP method, raw headers and request body, calls HTTP client and converts status code, raw headers and response body back to python objects.
Since adapter would provide an API purely for internal Lapidary use, it wouldn't need any facility methods like post, get and so on; a single method like exchange would suffice.
class Request(NamedTuple):
method: str
headers: list[tuple[str, str]]
content: AsyncIterator[bytes]
ssl: SSLContext
class Response(NamedTuple):
status_code: int
headers: list[tuple[str, str]]
content: AsyncIterator[bytes]
class HTTPConnectionError(Error):pass
async def exchange(request: Request)->Response:
"""
raises:
HTTPConnectionError: general error for when a HTTP response couldn't be obtained
"""