Skip to content

Commit

Permalink
restore test + improve NonHttpUrlRedirectClientError
Browse files Browse the repository at this point in the history
  • Loading branch information
setla committed Feb 9, 2024
1 parent 47a0043 commit 0c3a1a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class RedirectClientError(ClientError):
"""Client redirect error."""


class NonHttpUrlClientError(InvalidURL):
class NonHttpUrlClientError(ClientError):
"""Non http URL client error."""


Expand Down
2 changes: 1 addition & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0c3a1a3

Please sign in to comment.