Skip to content

Commit 7673674

Browse files
Create client transport interface
1 parent 8bced95 commit 7673674

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/HttpProtocolTestGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def __init__(self, *, client_config: HTTPClientConfiguration | None = None):
627627
self._client_config = client_config
628628
629629
async def send(
630-
self, *, request: HTTPRequest, request_config: HTTPRequestConfiguration | None = None
630+
self, request: HTTPRequest, *, request_config: HTTPRequestConfiguration | None = None
631631
) -> HTTPResponse:
632632
# Raise the exception with the request object to bypass actual request handling
633633
raise $1T(request)
@@ -650,7 +650,7 @@ def __init__(
650650
self.body = body
651651
652652
async def send(
653-
self, *, request: HTTPRequest, request_config: HTTPRequestConfiguration | None = None
653+
self, request: HTTPRequest, *, request_config: HTTPRequestConfiguration | None = None
654654
) -> _HTTPResponse:
655655
# Pre-construct the response from the request and return it
656656
return _HTTPResponse(

packages/smithy-core/src/smithy_core/aio/interfaces/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ async def write(self, data: bytes) -> None: ...
2727

2828

2929
class Request(Protocol):
30-
"""Protocol-agnostic representation of a request.
31-
32-
:param destination: The URI where the request should be sent to.
33-
:param body: The request payload as iterable of chunks of bytes.
34-
"""
30+
"""Protocol-agnostic representation of a request."""
3531

3632
destination: URI
33+
"""The URI where the request should be sent to."""
34+
3735
body: StreamingBlob = b""
36+
"""The request payload."""
3837

3938
async def consume_body_async(self) -> bytes:
4039
"""Iterate over request body and return as bytes."""
@@ -60,3 +59,11 @@ async def consume_body_async(self) -> bytes:
6059
def consume_body(self) -> bytes:
6160
"""Iterate over request body and return as bytes."""
6261
...
62+
63+
64+
class ClientTransport[I: Request, O: Response](Protocol):
65+
"""Protocol-agnostic representation of a client tranport (e.g. an HTTP client)."""
66+
67+
async def send(self, request: I) -> O:
68+
"""Send a request over the transport and receive the response."""
69+
...

packages/smithy-http/src/smithy_http/aio/aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def __init__(
6666

6767
async def send(
6868
self,
69-
*,
7069
request: HTTPRequest,
70+
*,
7171
request_config: HTTPRequestConfiguration | None = None,
7272
) -> HTTPResponseInterface:
7373
"""Send HTTP request using aiohttp client.

packages/smithy-http/src/smithy_http/aio/crt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def __init__(
197197

198198
async def send(
199199
self,
200-
*,
201200
request: http_aio_interfaces.HTTPRequest,
201+
*,
202202
request_config: http_aio_interfaces.HTTPRequestConfiguration | None = None,
203203
) -> AWSCRTHTTPResponse:
204204
"""Send HTTP request using awscrt client.

packages/smithy-http/src/smithy_http/aio/interfaces/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from typing import Protocol, TypeVar
44

5-
from smithy_core.aio.interfaces import Request, Response
5+
from smithy_core.aio.interfaces import Request, Response, ClientTransport
66
from smithy_core.aio.utils import read_streaming_blob, read_streaming_blob_async
77

88
from ...interfaces import (
@@ -75,7 +75,7 @@ def consume_body(self) -> bytes:
7575
return read_streaming_blob(self.body)
7676

7777

78-
class HTTPClient(Protocol):
78+
class HTTPClient(ClientTransport[HTTPRequest, HTTPResponse], Protocol):
7979
"""An asynchronous HTTP client interface."""
8080

8181
def __init__(self, *, client_config: HTTPClientConfiguration | None) -> None:
@@ -87,8 +87,8 @@ def __init__(self, *, client_config: HTTPClientConfiguration | None) -> None:
8787

8888
async def send(
8989
self,
90-
*,
9190
request: HTTPRequest,
91+
*,
9292
request_config: HTTPRequestConfiguration | None = None,
9393
) -> HTTPResponse:
9494
"""Send HTTP request over the wire and return the response.

0 commit comments

Comments
 (0)