Skip to content

Commit

Permalink
Switch auth/redirect methods to follow flow of execution better (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Sep 10, 2020
1 parent ed16eb3 commit 930f377
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,37 @@ def send(

return response

def _send_handling_auth(
self,
request: Request,
auth: Auth,
timeout: Timeout,
allow_redirects: bool,
history: typing.List[Response],
) -> Response:
auth_flow = auth.sync_auth_flow(request)
request = next(auth_flow)

while True:
response = self._send_handling_redirects(
request,
timeout=timeout,
allow_redirects=allow_redirects,
history=history,
)
try:
next_request = auth_flow.send(response)
except StopIteration:
return response
except BaseException as exc:
response.close()
raise exc from None
else:
response.history = list(history)
response.read()
request = next_request
history.append(response)

def _send_handling_redirects(
self,
request: Request,
Expand Down Expand Up @@ -775,37 +806,6 @@ def _send_handling_redirects(
)
return response

def _send_handling_auth(
self,
request: Request,
auth: Auth,
timeout: Timeout,
allow_redirects: bool,
history: typing.List[Response],
) -> Response:
auth_flow = auth.sync_auth_flow(request)
request = next(auth_flow)

while True:
response = self._send_handling_redirects(
request,
timeout=timeout,
allow_redirects=allow_redirects,
history=history,
)
try:
next_request = auth_flow.send(response)
except StopIteration:
return response
except BaseException as exc:
response.close()
raise exc from None
else:
response.history = list(history)
response.read()
request = next_request
history.append(response)

def _send_single_request(self, request: Request, timeout: Timeout) -> Response:
"""
Sends a single request, without handling any redirections.
Expand Down Expand Up @@ -1364,6 +1364,37 @@ async def send(

return response

async def _send_handling_auth(
self,
request: Request,
auth: Auth,
timeout: Timeout,
allow_redirects: bool,
history: typing.List[Response],
) -> Response:
auth_flow = auth.async_auth_flow(request)
request = await auth_flow.__anext__()

while True:
response = await self._send_handling_redirects(
request,
timeout=timeout,
allow_redirects=allow_redirects,
history=history,
)
try:
next_request = await auth_flow.asend(response)
except StopAsyncIteration:
return response
except BaseException as exc:
await response.aclose()
raise exc from None
else:
response.history = list(history)
await response.aread()
request = next_request
history.append(response)

async def _send_handling_redirects(
self,
request: Request,
Expand Down Expand Up @@ -1398,37 +1429,6 @@ async def _send_handling_redirects(
)
return response

async def _send_handling_auth(
self,
request: Request,
auth: Auth,
timeout: Timeout,
allow_redirects: bool,
history: typing.List[Response],
) -> Response:
auth_flow = auth.async_auth_flow(request)
request = await auth_flow.__anext__()

while True:
response = await self._send_handling_redirects(
request,
timeout=timeout,
allow_redirects=allow_redirects,
history=history,
)
try:
next_request = await auth_flow.asend(response)
except StopAsyncIteration:
return response
except BaseException as exc:
await response.aclose()
raise exc from None
else:
response.history = list(history)
await response.aread()
request = next_request
history.append(response)

async def _send_single_request(
self, request: Request, timeout: Timeout
) -> Response:
Expand Down

0 comments on commit 930f377

Please sign in to comment.