Skip to content

Commit 930f377

Browse files
authored
Switch auth/redirect methods to follow flow of execution better (#1273)
1 parent ed16eb3 commit 930f377

File tree

1 file changed

+62
-62
lines changed

1 file changed

+62
-62
lines changed

httpx/_client.py

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,37 @@ def send(
741741

742742
return response
743743

744+
def _send_handling_auth(
745+
self,
746+
request: Request,
747+
auth: Auth,
748+
timeout: Timeout,
749+
allow_redirects: bool,
750+
history: typing.List[Response],
751+
) -> Response:
752+
auth_flow = auth.sync_auth_flow(request)
753+
request = next(auth_flow)
754+
755+
while True:
756+
response = self._send_handling_redirects(
757+
request,
758+
timeout=timeout,
759+
allow_redirects=allow_redirects,
760+
history=history,
761+
)
762+
try:
763+
next_request = auth_flow.send(response)
764+
except StopIteration:
765+
return response
766+
except BaseException as exc:
767+
response.close()
768+
raise exc from None
769+
else:
770+
response.history = list(history)
771+
response.read()
772+
request = next_request
773+
history.append(response)
774+
744775
def _send_handling_redirects(
745776
self,
746777
request: Request,
@@ -775,37 +806,6 @@ def _send_handling_redirects(
775806
)
776807
return response
777808

778-
def _send_handling_auth(
779-
self,
780-
request: Request,
781-
auth: Auth,
782-
timeout: Timeout,
783-
allow_redirects: bool,
784-
history: typing.List[Response],
785-
) -> Response:
786-
auth_flow = auth.sync_auth_flow(request)
787-
request = next(auth_flow)
788-
789-
while True:
790-
response = self._send_handling_redirects(
791-
request,
792-
timeout=timeout,
793-
allow_redirects=allow_redirects,
794-
history=history,
795-
)
796-
try:
797-
next_request = auth_flow.send(response)
798-
except StopIteration:
799-
return response
800-
except BaseException as exc:
801-
response.close()
802-
raise exc from None
803-
else:
804-
response.history = list(history)
805-
response.read()
806-
request = next_request
807-
history.append(response)
808-
809809
def _send_single_request(self, request: Request, timeout: Timeout) -> Response:
810810
"""
811811
Sends a single request, without handling any redirections.
@@ -1364,6 +1364,37 @@ async def send(
13641364

13651365
return response
13661366

1367+
async def _send_handling_auth(
1368+
self,
1369+
request: Request,
1370+
auth: Auth,
1371+
timeout: Timeout,
1372+
allow_redirects: bool,
1373+
history: typing.List[Response],
1374+
) -> Response:
1375+
auth_flow = auth.async_auth_flow(request)
1376+
request = await auth_flow.__anext__()
1377+
1378+
while True:
1379+
response = await self._send_handling_redirects(
1380+
request,
1381+
timeout=timeout,
1382+
allow_redirects=allow_redirects,
1383+
history=history,
1384+
)
1385+
try:
1386+
next_request = await auth_flow.asend(response)
1387+
except StopAsyncIteration:
1388+
return response
1389+
except BaseException as exc:
1390+
await response.aclose()
1391+
raise exc from None
1392+
else:
1393+
response.history = list(history)
1394+
await response.aread()
1395+
request = next_request
1396+
history.append(response)
1397+
13671398
async def _send_handling_redirects(
13681399
self,
13691400
request: Request,
@@ -1398,37 +1429,6 @@ async def _send_handling_redirects(
13981429
)
13991430
return response
14001431

1401-
async def _send_handling_auth(
1402-
self,
1403-
request: Request,
1404-
auth: Auth,
1405-
timeout: Timeout,
1406-
allow_redirects: bool,
1407-
history: typing.List[Response],
1408-
) -> Response:
1409-
auth_flow = auth.async_auth_flow(request)
1410-
request = await auth_flow.__anext__()
1411-
1412-
while True:
1413-
response = await self._send_handling_redirects(
1414-
request,
1415-
timeout=timeout,
1416-
allow_redirects=allow_redirects,
1417-
history=history,
1418-
)
1419-
try:
1420-
next_request = await auth_flow.asend(response)
1421-
except StopAsyncIteration:
1422-
return response
1423-
except BaseException as exc:
1424-
await response.aclose()
1425-
raise exc from None
1426-
else:
1427-
response.history = list(history)
1428-
await response.aread()
1429-
request = next_request
1430-
history.append(response)
1431-
14321432
async def _send_single_request(
14331433
self, request: Request, timeout: Timeout
14341434
) -> Response:

0 commit comments

Comments
 (0)