Drop RedirectLoop exception (#819)

* drop RedirectLoop exception

* tests is package to allow run it easly

* bring back test for redirect loop
This commit is contained in:
Piotr Staroszczyk 2020-02-24 11:09:52 +01:00 committed by GitHub
parent db33c071e1
commit efe9f61bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 4 additions and 33 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ site/
*.egg-info/ *.egg-info/
venv*/ venv*/
.python-version .python-version
build/
dist/

View File

@ -18,7 +18,6 @@ from ._exceptions import (
ProtocolError, ProtocolError,
ProxyError, ProxyError,
ReadTimeout, ReadTimeout,
RedirectLoop,
RequestBodyUnavailable, RequestBodyUnavailable,
RequestNotRead, RequestNotRead,
ResponseClosed, ResponseClosed,
@ -66,7 +65,6 @@ __all__ = [
"PoolTimeout", "PoolTimeout",
"ProtocolError", "ProtocolError",
"ReadTimeout", "ReadTimeout",
"RedirectLoop",
"RequestBodyUnavailable", "RequestBodyUnavailable",
"ResponseClosed", "ResponseClosed",
"ResponseNotRead", "ResponseNotRead",

View File

@ -27,13 +27,7 @@ from ._dispatch.connection_pool import ConnectionPool
from ._dispatch.proxy_http import HTTPProxy from ._dispatch.proxy_http import HTTPProxy
from ._dispatch.urllib3 import URLLib3Dispatcher from ._dispatch.urllib3 import URLLib3Dispatcher
from ._dispatch.wsgi import WSGIDispatch from ._dispatch.wsgi import WSGIDispatch
from ._exceptions import ( from ._exceptions import HTTPError, InvalidURL, RequestBodyUnavailable, TooManyRedirects
HTTPError,
InvalidURL,
RedirectLoop,
RequestBodyUnavailable,
TooManyRedirects,
)
from ._models import ( from ._models import (
URL, URL,
Cookies, Cookies,
@ -615,9 +609,6 @@ class Client(BaseClient):
while True: while True:
if len(history) > self.max_redirects: if len(history) > self.max_redirects:
raise TooManyRedirects() 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( response = self.send_handling_auth(
request, auth=auth, timeout=timeout, history=history request, auth=auth, timeout=timeout, history=history
@ -1142,9 +1133,6 @@ class AsyncClient(BaseClient):
while True: while True:
if len(history) > self.max_redirects: if len(history) > self.max_redirects:
raise TooManyRedirects() 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( response = await self.send_handling_auth(
request, auth=auth, timeout=timeout, history=history request, auth=auth, timeout=timeout, history=history

View File

@ -101,12 +101,6 @@ class TooManyRedirects(RedirectError):
""" """
class RedirectLoop(RedirectError):
"""
Infinite redirect loop.
"""
class NotRedirectResponse(RedirectError): class NotRedirectResponse(RedirectError):
""" """
Response was not a redirect response. Response was not a redirect response.

0
tests/__init__.py Normal file
View File

View File

@ -7,7 +7,6 @@ from httpx import (
URL, URL,
AsyncClient, AsyncClient,
NotRedirectResponse, NotRedirectResponse,
RedirectLoop,
Request, Request,
RequestBodyUnavailable, RequestBodyUnavailable,
Response, Response,
@ -245,20 +244,10 @@ async def test_too_many_redirects_calling_next():
@pytest.mark.usefixtures("async_environment") @pytest.mark.usefixtures("async_environment")
async def test_redirect_loop(): async def test_redirect_loop():
client = AsyncClient(dispatch=MockDispatch()) client = AsyncClient(dispatch=MockDispatch())
with pytest.raises(RedirectLoop): with pytest.raises(TooManyRedirects):
await client.get("https://example.org/redirect_loop") 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") @pytest.mark.usefixtures("async_environment")
async def test_cross_domain_redirect(): async def test_cross_domain_redirect():
client = AsyncClient(dispatch=MockDispatch()) client = AsyncClient(dispatch=MockDispatch())