|  | 
| 4 | 4 | #  flake8: noqa: F811 | 
| 5 | 5 | from collections.abc import AsyncGenerator, AsyncIterable | 
| 6 | 6 | from copy import deepcopy | 
|  | 7 | +from dataclasses import dataclass | 
| 7 | 8 | from inspect import iscoroutinefunction | 
| 8 | 9 | from typing import TYPE_CHECKING, Any | 
| 9 | 10 | 
 | 
|  | 
| 41 | 42 | from ..interfaces import FieldPosition | 
| 42 | 43 | from . import interfaces as http_aio_interfaces | 
| 43 | 44 | 
 | 
|  | 45 | +# Default buffer size for reading from streams (8 KB) | 
|  | 46 | +DEFAULT_READ_BUFFER_SIZE = 8192 | 
|  | 47 | + | 
| 44 | 48 | 
 | 
| 45 | 49 | def _assert_crt() -> None: | 
| 46 | 50 |     if not HAS_CRT: | 
| @@ -111,7 +115,16 @@ def __repr__(self) -> str: | 
| 111 | 115 | ConnectionPoolDict = dict[ConnectionPoolKey, "AIOHttpClientConnectionUnified"] | 
| 112 | 116 | 
 | 
| 113 | 117 | 
 | 
|  | 118 | +@dataclass(kw_only=True) | 
| 114 | 119 | 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 | + | 
| 115 | 128 |     def __post_init__(self) -> None: | 
| 116 | 129 |         _assert_crt() | 
| 117 | 130 | 
 | 
| @@ -307,7 +320,7 @@ async def _create_body_generator( | 
| 307 | 320 |         ): | 
| 308 | 321 |             # AsyncByteStream has async read method but is not iterable | 
| 309 | 322 |             while True: | 
| 310 |  | -                chunk = await body.read() | 
|  | 323 | +                chunk = await body.read(self._config.read_buffer_size) | 
| 311 | 324 |                 if not chunk: | 
| 312 | 325 |                     break | 
| 313 | 326 |                 if isinstance(chunk, bytearray): | 
|  | 
0 commit comments