Skip to content

Commit 7411240

Browse files
committed
Use 8KB buffer default size and make it configurable
1 parent 02e3e20 commit 7411240

File tree

1 file changed

+14
-1
lines changed
  • packages/smithy-http/src/smithy_http/aio

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# flake8: noqa: F811
55
from collections.abc import AsyncGenerator, AsyncIterable
66
from copy import deepcopy
7+
from dataclasses import dataclass
78
from inspect import iscoroutinefunction
89
from typing import TYPE_CHECKING, Any
910

@@ -41,6 +42,9 @@
4142
from ..interfaces import FieldPosition
4243
from . import interfaces as http_aio_interfaces
4344

45+
# Default buffer size for reading from streams (8 KB)
46+
DEFAULT_READ_BUFFER_SIZE = 8192
47+
4448

4549
def _assert_crt() -> None:
4650
if not HAS_CRT:
@@ -111,7 +115,16 @@ def __repr__(self) -> str:
111115
ConnectionPoolDict = dict[ConnectionPoolKey, "AIOHttpClientConnectionUnified"]
112116

113117

118+
@dataclass(kw_only=True)
114119
class AWSCRTHTTPClientConfig(http_interfaces.HTTPClientConfiguration):
120+
"""AWS CRT HTTP client configuration.
121+
122+
:param read_buffer_size: The buffer size in bytes to use when reading from streams.
123+
Defaults to 8192 (8 KB).
124+
"""
125+
126+
read_buffer_size: int = DEFAULT_READ_BUFFER_SIZE
127+
115128
def __post_init__(self) -> None:
116129
_assert_crt()
117130

@@ -307,7 +320,7 @@ async def _create_body_generator(
307320
):
308321
# AsyncByteStream has async read method but is not iterable
309322
while True:
310-
chunk = await body.read()
323+
chunk = await body.read(self._config.read_buffer_size)
311324
if not chunk:
312325
break
313326
if isinstance(chunk, bytearray):

0 commit comments

Comments
 (0)