Drop RedirectLoop exception (#819)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* drop RedirectLoop exception * tests is package to allow run it easly * bring back test for redirect loop
authored by Piotr Staroszczyk · committed by GitHub · parent db33c07 · Browse files · 6 files·+4 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+4 added−33 removed
- tests:+1 added−12 removed
- other:+3 added−21 removed
Provenance
- Commit
efe9f61- Tree
66445f4- Author
Piotr Staroszczyk <oczkers@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
db33c07
6 files changed+4 added−33 removed
modified:httpx/__init__.py-2 removed
16 unmodified lines17 PoolTimeout,18 ProtocolError,19 ProxyError,20 ReadTimeout,21- RedirectLoop,21 RequestBodyUnavailable,22 RequestNotRead,23 ResponseClosed,24 ResponseNotRead,39 unmodified lines64 "NotRedirectResponse",65 "PoolTimeout",66 "ProtocolError",67 "ReadTimeout",69- "RedirectLoop",68 "RequestBodyUnavailable",69 "ResponseClosed",70 "ResponseNotRead",71 "RequestNotRead",15 unmodified linesmodified:httpx/_client.py+1 added-13 removed
25 unmodified lines26 from ._dispatch.connection_pool import ConnectionPool27 from ._dispatch.proxy_http import HTTPProxy28 from ._dispatch.urllib3 import URLLib3Dispatcher29 from ._dispatch.wsgi import WSGIDispatch30-from ._exceptions import (31- HTTPError,32- InvalidURL,33- RedirectLoop,34- RequestBodyUnavailable,35- TooManyRedirects,36-)30+from ._exceptions import HTTPError, InvalidURL, RequestBodyUnavailable, TooManyRedirects31 from ._models import (32 URL,33 Cookies,34 CookieTypes,573 unmodified lines608 609 while True:610 if len(history) > self.max_redirects:611 raise TooManyRedirects()618- urls = ((resp.request.method, resp.url) for resp in history)619- if (request.method, request.url) in urls:620- raise RedirectLoop()612 613 response = self.send_handling_auth(614 request, auth=auth, timeout=timeout, history=history615 )516 unmodified lines1132 1133 while True:1134 if len(history) > self.max_redirects:1135 raise TooManyRedirects()1145- urls = ((resp.request.method, resp.url) for resp in history)1146- if (request.method, request.url) in urls:1147- raise RedirectLoop()1136 1137 response = await self.send_handling_auth(1138 request, auth=auth, timeout=timeout, history=history1139 )325 unmodified linesmodified:httpx/_exceptions.py-6 removed
99 unmodified lines100 Too many redirects.101 """102 103 104-class RedirectLoop(RedirectError):105- """106- Infinite redirect loop.107- """108-109-104 class NotRedirectResponse(RedirectError):105 """106 Response was not a redirect response.107 """61 unmodified linesmodified:tests/client/test_redirects.py+1 added-12 removed
5 unmodified lines6 from httpx import (7 URL,8 AsyncClient,9 NotRedirectResponse,10- RedirectLoop,10 Request,11 RequestBodyUnavailable,12 Response,13 TooManyRedirects,229 unmodified lines243 244 @pytest.mark.usefixtures("async_environment")245 async def test_redirect_loop():246 client = AsyncClient(dispatch=MockDispatch())248- with pytest.raises(RedirectLoop):247+ with pytest.raises(TooManyRedirects):248 await client.get("https://example.org/redirect_loop")249 250 251 @pytest.mark.usefixtures("async_environment")253-async def test_redirect_loop_calling_next():254- client = AsyncClient(dispatch=MockDispatch())255- url = "https://example.org/redirect_loop"256- response = await client.get(url, allow_redirects=False)257- with pytest.raises(RedirectLoop):258- while response.is_redirect:259- response = await response.anext()260-261-262-@pytest.mark.usefixtures("async_environment")252 async def test_cross_domain_redirect():253 client = AsyncClient(dispatch=MockDispatch())254 url = "https://example.com/cross_domain"255 headers = {"Authorization": "abc"}140 unmodified linesadded:tests/__init__.py
modified:.gitignore+2 added
6 unmodified lines7 site/8 *.egg-info/9 venv*/10 .python-version11+build/12+dist/