Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/10902.feature.rst
8 changes: 4 additions & 4 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
List,
Mapping,
Optional,
Sequence,
Set,
Tuple,
Type,
Expand Down Expand Up @@ -192,7 +193,7 @@ class _RequestOptions(TypedDict, total=False):
auto_decompress: Union[bool, None]
max_line_size: Union[int, None]
max_field_size: Union[int, None]
middlewares: Optional[Tuple[ClientMiddlewareType, ...]]
middlewares: Optional[Sequence[ClientMiddlewareType]]


@attr.s(auto_attribs=True, frozen=True, slots=True)
Expand Down Expand Up @@ -301,7 +302,7 @@ def __init__(
max_line_size: int = 8190,
max_field_size: int = 8190,
fallback_charset_resolver: _CharsetResolver = lambda r, b: "utf-8",
middlewares: Optional[Tuple[ClientMiddlewareType, ...]] = None,
middlewares: Optional[Sequence[ClientMiddlewareType]] = None,
) -> None:
# We initialise _connector to None immediately, as it's referenced in __del__()
# and could cause issues if an exception occurs during initialisation.
Expand Down Expand Up @@ -505,7 +506,7 @@ async def _request(
auto_decompress: Optional[bool] = None,
max_line_size: Optional[int] = None,
max_field_size: Optional[int] = None,
middlewares: Optional[Tuple[ClientMiddlewareType, ...]] = None,
middlewares: Optional[Sequence[ClientMiddlewareType]] = None,
) -> ClientResponse:

# NOTE: timeout clamps existing connect and read timeouts. We cannot
Expand Down Expand Up @@ -705,7 +706,6 @@ async def _request(
trust_env=self.trust_env,
)

# Core request handler - now includes connection logic
async def _connect_and_send_request(
req: ClientRequest,
) -> ClientResponse:
Expand Down
7 changes: 2 additions & 5 deletions aiohttp/client_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Client middleware support."""

from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Sequence

from .client_reqrep import ClientRequest, ClientResponse

Expand All @@ -17,7 +17,7 @@

def build_client_middlewares(
handler: ClientHandlerType,
middlewares: tuple[ClientMiddlewareType, ...],
middlewares: Sequence[ClientMiddlewareType],
) -> ClientHandlerType:
"""
Apply middlewares to request handler.
Expand All @@ -28,9 +28,6 @@ def build_client_middlewares(
This implementation avoids using partial/update_wrapper to minimize overhead
and doesn't cache to avoid holding references to stateful middleware.
"""
if not middlewares:
return handler

# Optimize for single middleware case
if len(middlewares) == 1:
middleware = middlewares[0]
Expand Down
Loading
Loading