]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop RedirectLoop exception (#819)
authorPiotr Staroszczyk <oczkers@gmail.com>
Mon, 24 Feb 2020 10:09:52 +0000 (11:09 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2020 10:09:52 +0000 (10:09 +0000)
* drop RedirectLoop exception

* tests is package to allow run it easly

* bring back test for redirect loop

.gitignore
httpx/__init__.py
httpx/_client.py
httpx/_exceptions.py
tests/__init__.py [new file with mode: 0644]
tests/client/test_redirects.py

index 22e1fbfeba8dc48ed6ba0a76f37ad44ed897a6a2..49e14ccc8ddce6b1390b122f4a9cdc18cd1a41b4 100644 (file)
@@ -8,3 +8,5 @@ site/
 *.egg-info/
 venv*/
 .python-version
+build/
+dist/
index 2c4cb7276a37f3303468dc9467e58a080c06f518..d02c72e9f1a62be381b8bebd54721f14d3f4183a 100644 (file)
@@ -18,7 +18,6 @@ from ._exceptions import (
     ProtocolError,
     ProxyError,
     ReadTimeout,
-    RedirectLoop,
     RequestBodyUnavailable,
     RequestNotRead,
     ResponseClosed,
@@ -66,7 +65,6 @@ __all__ = [
     "PoolTimeout",
     "ProtocolError",
     "ReadTimeout",
-    "RedirectLoop",
     "RequestBodyUnavailable",
     "ResponseClosed",
     "ResponseNotRead",
index 6c8785894771f994bb14eb29dcde8d2b72bffa74..472d455953a9bf685223af6ae801e921842bfb80 100644 (file)
@@ -27,13 +27,7 @@ from ._dispatch.connection_pool import ConnectionPool
 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,
@@ -615,9 +609,6 @@ class Client(BaseClient):
         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
@@ -1142,9 +1133,6 @@ class AsyncClient(BaseClient):
         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
index 562c2ed62cff19c3b5f7c8d31408bd5f6989375b..0f0ea062d32e251da98cc8a2b9fc73eddd4f7c59 100644 (file)
@@ -101,12 +101,6 @@ class TooManyRedirects(RedirectError):
     """
 
 
-class RedirectLoop(RedirectError):
-    """
-    Infinite redirect loop.
-    """
-
-
 class NotRedirectResponse(RedirectError):
     """
     Response was not a redirect response.
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index ad138e52bfa009bfbde9f0f955ecd0a07178829f..190ff0940921931fccf01d750457a10e942c108f 100644 (file)
@@ -7,7 +7,6 @@ from httpx import (
     URL,
     AsyncClient,
     NotRedirectResponse,
-    RedirectLoop,
     Request,
     RequestBodyUnavailable,
     Response,
@@ -245,20 +244,10 @@ async def test_too_many_redirects_calling_next():
 @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())