-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path__init__.py
More file actions
103 lines (79 loc) · 3.21 KB
/
__init__.py
File metadata and controls
103 lines (79 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Protocol
from smithy_core.aio.interfaces import ClientTransport, Request, Response
from smithy_core.aio.utils import read_streaming_blob, read_streaming_blob_async
from smithy_core.schemas import APIOperation
from smithy_core.shapes import ShapeID
from ...interfaces import (
Fields,
HTTPClientConfiguration,
HTTPRequestConfiguration,
)
class HTTPRequest(Request, Protocol):
"""HTTP primitive for an Exchange to construct a version agnostic HTTP message.
:param destination: The URI where the request should be sent to.
:param method: The HTTP method of the request, for example "GET".
:param fields: ``Fields`` object containing HTTP headers and trailers.
:param body: A streamable collection of bytes.
"""
method: str
fields: Fields
async def consume_body_async(self) -> bytes:
"""Iterate over request body and return as bytes."""
return await read_streaming_blob_async(self.body)
def consume_body(self) -> bytes:
"""Iterate over request body and return as bytes."""
return read_streaming_blob(self.body)
class HTTPResponse(Response, Protocol):
"""HTTP primitives returned from an Exchange, used to construct a client
response."""
@property
def status(self) -> int:
"""The 3 digit response status code (1xx, 2xx, 3xx, 4xx, 5xx)."""
...
@property
def fields(self) -> Fields:
"""``Fields`` object containing HTTP headers and trailers."""
...
@property
def reason(self) -> str | None:
"""Optional string provided by the server explaining the status."""
...
async def consume_body_async(self) -> bytes:
"""Iterate over request body and return as bytes."""
return await read_streaming_blob_async(self.body)
def consume_body(self) -> bytes:
"""Iterate over request body and return as bytes."""
return read_streaming_blob(self.body)
class HTTPClient(ClientTransport[HTTPRequest, HTTPResponse], Protocol):
"""An asynchronous HTTP client interface."""
def __init__(self, *, client_config: HTTPClientConfiguration | None) -> None:
"""
:param client_config: Configuration that applies to all requests made with this
client.
"""
...
async def send(
self,
request: HTTPRequest,
*,
request_config: HTTPRequestConfiguration | None = None,
) -> HTTPResponse:
"""Send HTTP request over the wire and return the response.
:param request: The request including destination URI, fields, payload.
:param request_config: Configuration specific to this request.
"""
...
class HTTPErrorIdentifier:
"""A class that uses HTTP response metadata to identify errors.
The body of the response SHOULD NOT be touched by this. The payload codec will be
used instead to check for an ID in the body.
"""
def identify(
self,
*,
operation: APIOperation[Any, Any],
response: HTTPResponse,
) -> ShapeID | None:
"""Idenitfy the ShapeID of an error from an HTTP response."""