Skip to content

Commit a1ab9c6

Browse files
authored
Switch to yarl for building the request URL (#10)
aiohttp is going to convert it to a URL object internally and its a bit more efficient to pass a URL object to request
1 parent 586ed9f commit a1ab9c6

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

go2rtc_client/rest.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import logging
66
from typing import TYPE_CHECKING, Any, Final, Literal
7-
from urllib.parse import urljoin
87

98
from aiohttp import ClientError, ClientResponse, ClientSession
109
from aiohttp.client import _RequestOptions
1110
from mashumaro.codecs.basic import BasicDecoder
1211
from mashumaro.mixins.dict import DataClassDictMixin
12+
from yarl import URL
1313

1414
from .models import Stream, WebRTCSdpAnswer, WebRTCSdpOffer
1515

@@ -27,7 +27,7 @@ class _BaseClient:
2727
def __init__(self, websession: ClientSession, server_url: str) -> None:
2828
"""Initialize Client."""
2929
self._session = websession
30-
self._base_url = server_url
30+
self._base_url = URL(server_url)
3131

3232
async def request(
3333
self,
@@ -38,7 +38,7 @@ async def request(
3838
data: DataClassDictMixin | dict[str, Any] | None = None,
3939
) -> ClientResponse:
4040
"""Make a request to the server."""
41-
url = self._request_url(path)
41+
url = self._base_url.with_path(path)
4242
_LOGGER.debug("request[%s] %s", method, url)
4343
if isinstance(data, DataClassDictMixin):
4444
data = data.to_dict()
@@ -56,10 +56,6 @@ async def request(
5656
resp.raise_for_status()
5757
return resp
5858

59-
def _request_url(self, path: str) -> str:
60-
"""Return a request url for the specific path."""
61-
return urljoin(self._base_url, path)
62-
6359

6460
class _WebRTCClient:
6561
"""Client for WebRTC module."""

0 commit comments

Comments
 (0)