From 0c3a1a3db763ad0360ef83e4ee3739f34e61045a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Setla?= Date: Fri, 9 Feb 2024 08:49:49 +0100 Subject: [PATCH] restore test + improve NonHttpUrlRedirectClientError --- aiohttp/client.py | 4 +--- aiohttp/client_exceptions.py | 2 +- docs/client_reference.rst | 2 +- tests/test_client_functional.py | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index 52cde5565a3..c5ab724fe40 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -633,9 +633,7 @@ async def _request( scheme = parsed_redirect_url.scheme if scheme not in ("http", "https", ""): resp.close() - raise NonHttpUrlRedirectClientError( - r_url, "Can redirect only to http or https" - ) + raise NonHttpUrlRedirectClientError(r_url) elif not scheme: parsed_redirect_url = url.join(parsed_redirect_url) diff --git a/aiohttp/client_exceptions.py b/aiohttp/client_exceptions.py index 05e7977e1a0..cfe54803feb 100644 --- a/aiohttp/client_exceptions.py +++ b/aiohttp/client_exceptions.py @@ -289,7 +289,7 @@ class RedirectClientError(ClientError): """Client redirect error.""" -class NonHttpUrlClientError(InvalidURL): +class NonHttpUrlClientError(ClientError): """Non http URL client error.""" diff --git a/docs/client_reference.rst b/docs/client_reference.rst index 5f7b79e9c43..2793530f3a9 100644 --- a/docs/client_reference.rst +++ b/docs/client_reference.rst @@ -2119,7 +2119,7 @@ All exceptions are available as members of *aiohttp* module. Base class for all errors related to non http client urls. - Derived from :exc:`InvalidURL` + Derived from :exc:`ClientError` .. exception:: InvalidUrlRedirectClientError diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 08b3cfed7ba..f2997bda96a 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -2490,8 +2490,10 @@ async def test_invalid_redirect_url( error_message_url: str, expected_exception_class: Any, ) -> None: + headers = {hdrs.LOCATION: invalid_redirect_url} + async def generate_redirecting_response(request): - raise web.HTTPFound(location=invalid_redirect_url) + return web.Response(status=301, headers=headers) app = web.Application() app.router.add_get("/redirect", generate_redirecting_response)