From efe9f61bc2f047574c7b78bbd3d00ca74f930196 Mon Sep 17 00:00:00 2001 From: Piotr Staroszczyk Date: Mon, 24 Feb 2020 11:09:52 +0100 Subject: [PATCH] Drop RedirectLoop exception (#819) * drop RedirectLoop exception * tests is package to allow run it easly * bring back test for redirect loop --- .gitignore | 2 ++ httpx/__init__.py | 2 -- httpx/_client.py | 14 +------------- httpx/_exceptions.py | 6 ------ tests/__init__.py | 0 tests/client/test_redirects.py | 13 +------------ 6 files changed, 4 insertions(+), 33 deletions(-) create mode 100644 tests/__init__.py diff --git a/.gitignore b/.gitignore index 22e1fbfe..49e14ccc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ site/ *.egg-info/ venv*/ .python-version +build/ +dist/ diff --git a/httpx/__init__.py b/httpx/__init__.py index 2c4cb727..d02c72e9 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -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", diff --git a/httpx/_client.py b/httpx/_client.py index 6c878589..472d4559 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -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 diff --git a/httpx/_exceptions.py b/httpx/_exceptions.py index 562c2ed6..0f0ea062 100644 --- a/httpx/_exceptions.py +++ b/httpx/_exceptions.py @@ -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 index 00000000..e69de29b diff --git a/tests/client/test_redirects.py b/tests/client/test_redirects.py index ad138e52..190ff094 100644 --- a/tests/client/test_redirects.py +++ b/tests/client/test_redirects.py @@ -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()) -- 2.47.3