Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
28 changes: 16 additions & 12 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,23 @@ async def _request(
get_env_proxy_for_url, url
)

response_params = {
"timer": timer,
"skip_payload": method in EMPTY_BODY_METHODS,
"read_until_eof": read_until_eof,
"auto_decompress": auto_decompress,
"read_timeout": real_timeout.sock_read,
"read_bufsize": read_bufsize,
"timeout_ceil_threshold": self._connector._timeout_ceil_threshold,
"max_line_size": max_line_size,
"max_field_size": max_field_size,
}

req = self._request_class(
method,
url,
response_params=response_params,
timeout=real_timeout,
params=params,
headers=headers,
skip_auto_headers=skip_headers,
Expand Down Expand Up @@ -656,25 +670,15 @@ async def _connect_and_send_request(
assert self._connector is not None
try:
conn = await self._connector.connect(
req, traces=traces, timeout=real_timeout
req, traces=traces, timeout=req._timeout
)
except asyncio.TimeoutError as exc:
raise ConnectionTimeoutError(
f"Connection timeout to host {req.url}"
) from exc

assert conn.protocol is not None
conn.protocol.set_response_params(
timer=timer,
skip_payload=req.method in EMPTY_BODY_METHODS,
read_until_eof=read_until_eof,
auto_decompress=auto_decompress,
read_timeout=real_timeout.sock_read,
read_bufsize=read_bufsize,
timeout_ceil_threshold=self._connector._timeout_ceil_threshold,
max_line_size=max_line_size,
max_field_size=max_field_size,
)
conn.protocol.set_response_params(**req._response_params)
try:
resp = await req.send(conn)
try:
Expand Down
19 changes: 19 additions & 0 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Optional,
Tuple,
Type,
TypedDict,
Union,
)

Expand Down Expand Up @@ -77,6 +78,8 @@
if TYPE_CHECKING:
import ssl
from ssl import SSLContext

from .client import ClientTimeout
else:
try:
import ssl
Expand Down Expand Up @@ -190,6 +193,18 @@
proxy_headers_hash: Optional[int] # hash(CIMultiDict)


class _ResponseParams(TypedDict):
timer: Optional[BaseTimerContext]
skip_payload: bool
read_until_eof: bool
auto_decompress: bool
read_timeout: Optional[float]
read_bufsize: int
timeout_ceil_threshold: float
max_line_size: int
max_field_size: int


class ClientRequest:
GET_METHODS = {
hdrs.METH_GET,
Expand Down Expand Up @@ -251,6 +266,8 @@
traces: Optional[List["Trace"]] = None,
trust_env: bool = False,
server_hostname: Optional[str] = None,
response_params: Optional[_ResponseParams] = None,
timeout: Optional["ClientTimeout"] = None,
):
if match := _CONTAINS_CONTROL_CHAR_RE.search(method):
raise ValueError(
Expand Down Expand Up @@ -281,6 +298,8 @@
self.response_class: Type[ClientResponse] = real_response_class
self._timer = timer if timer is not None else TimerNoop()
self._ssl = ssl
self._response_params = response_params
self._timeout = timeout
self.server_hostname = server_hostname

if loop.get_debug():
Expand Down
Loading