from ._dispatch.proxy_http import HTTPProxy
from ._dispatch.urllib3 import URLLib3Dispatcher
from ._dispatch.wsgi import WSGIDispatch
-from ._exceptions import (
- HTTPError,
- InvalidURL,
- RedirectLoop,
- RequestBodyUnavailable,
- TooManyRedirects,
-)
+from ._exceptions import HTTPError, InvalidURL, RequestBodyUnavailable, TooManyRedirects
from ._models import (
URL,
Cookies,
while True:
if len(history) > self.max_redirects:
raise TooManyRedirects()
- urls = ((resp.request.method, resp.url) for resp in history)
- if (request.method, request.url) in urls:
- raise RedirectLoop()
response = self.send_handling_auth(
request, auth=auth, timeout=timeout, history=history
while True:
if len(history) > self.max_redirects:
raise TooManyRedirects()
- urls = ((resp.request.method, resp.url) for resp in history)
- if (request.method, request.url) in urls:
- raise RedirectLoop()
response = await self.send_handling_auth(
request, auth=auth, timeout=timeout, history=history
"""
-class RedirectLoop(RedirectError):
- """
- Infinite redirect loop.
- """
-
-
class NotRedirectResponse(RedirectError):
"""
Response was not a redirect response.
URL,
AsyncClient,
NotRedirectResponse,
- RedirectLoop,
Request,
RequestBodyUnavailable,
Response,
@pytest.mark.usefixtures("async_environment")
async def test_redirect_loop():
client = AsyncClient(dispatch=MockDispatch())
- with pytest.raises(RedirectLoop):
+ with pytest.raises(TooManyRedirects):
await client.get("https://example.org/redirect_loop")
-@pytest.mark.usefixtures("async_environment")
-async def test_redirect_loop_calling_next():
- client = AsyncClient(dispatch=MockDispatch())
- url = "https://example.org/redirect_loop"
- response = await client.get(url, allow_redirects=False)
- with pytest.raises(RedirectLoop):
- while response.is_redirect:
- response = await response.anext()
-
-
@pytest.mark.usefixtures("async_environment")
async def test_cross_domain_redirect():
client = AsyncClient(dispatch=MockDispatch())