Skip to content

Commit

Permalink
Use URL.join()
Browse files Browse the repository at this point in the history
  • Loading branch information
derlih committed Oct 28, 2021
1 parent 3af7031 commit 644f5a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
13 changes: 4 additions & 9 deletions aiohttp/client.py
Expand Up @@ -311,13 +311,11 @@ def request(
"""Perform HTTP request."""
return _RequestContextManager(self._request(method, url, **kwargs))

def _build_url(self, url: str) -> URL:
def _build_url(self, str_or_url: StrOrURL) -> URL:
if self._base_url is None:
return URL(url)
elif url.startswith("/"):
return self._base_url / url[1:]
return URL(str_or_url)
else:
raise ValueError("url must start with /")
return self._base_url.join(URL(str_or_url))

async def _request(
self,
Expand Down Expand Up @@ -378,10 +376,7 @@ async def _request(
proxy_headers = self._prepare_headers(proxy_headers)

try:
if isinstance(str_or_url, URL):
url = str_or_url
else:
url = self._build_url(str_or_url)
url = self._build_url(str_or_url)
except ValueError as e:
raise InvalidURL(str_or_url) from e

Expand Down
6 changes: 0 additions & 6 deletions tests/test_client_session.py
Expand Up @@ -725,12 +725,6 @@ async def test_build_url_returns_expected_url(
assert session._build_url(url) == expected_url


async def test_build_url_raises_when_url_not_starts_with_slash(create_session) -> None:
session = await create_session("http://example.com")
with pytest.raises(ValueError, match="url must start with /"):
session._build_url("test")


async def test_request_uses_base_url_when_url_is_str(create_session) -> None:
request_class = mock.MagicMock()
session = await create_session("http://example.com", request_class=request_class)
Expand Down

0 comments on commit 644f5a3

Please sign in to comment.