diff --git a/httpx/_client.py b/httpx/_client.py index 553ac7609a..21f3715f8e 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -849,13 +849,15 @@ def _send_single_request(self, request: Request, timeout: Timeout) -> Response: timer = Timer() timer.sync_start() + ext = request.ext.copy() + ext["timeout"] = timeout.as_dict() with map_exceptions(HTTPCORE_EXC_MAP, request=request): (status_code, headers, stream, ext) = transport.request( request.method.encode(), request.url.raw, headers=request.headers.raw, stream=request.stream, # type: ignore - ext={"timeout": timeout.as_dict()}, + ext=ext, ) def on_close(response: Response) -> None: @@ -1494,13 +1496,15 @@ async def _send_single_request( timer = Timer() await timer.async_start() + ext = request.ext.copy() + ext["timeout"] = timeout.as_dict() with map_exceptions(HTTPCORE_EXC_MAP, request=request): (status_code, headers, stream, ext,) = await transport.arequest( request.method.encode(), request.url.raw, headers=request.headers.raw, stream=request.stream, # type: ignore - ext={"timeout": timeout.as_dict()}, + ext=ext, ) async def on_close(response: Response) -> None: diff --git a/httpx/_models.py b/httpx/_models.py index 4ef35ed88a..ae0d6680b5 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -760,6 +760,7 @@ def __init__( files: RequestFiles = None, json: typing.Any = None, stream: ByteStream = None, + ext: dict = None, ): if isinstance(method, bytes): self.method = method.decode("ascii").upper() @@ -769,6 +770,7 @@ def __init__( self.headers = Headers(headers) if cookies: Cookies(cookies).set_cookie_header(self) + self.ext = {} if ext is None else ext if stream is not None: # There's an important distinction between `Request(content=...)`,