Skip to content

Commit

Permalink
Allow passing an ext to a Request
Browse files Browse the repository at this point in the history
  • Loading branch information
johtso committed Sep 28, 2020
1 parent 32d37cf commit c090d99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions httpx/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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=...)`,
Expand Down

0 comments on commit c090d99

Please sign in to comment.