Skip to content

Commit

Permalink
feat: speed up url joins (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 19, 2024
1 parent 2a65bff commit a10fc5a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/uiprotect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ipaddress import IPv4Address, IPv6Address
from pathlib import Path
from typing import Any, Literal, cast
from urllib.parse import urljoin
from urllib.parse import SplitResult

import aiofiles
import aiohttp
Expand Down Expand Up @@ -327,7 +327,9 @@ async def request(
if require_auth:
await self.ensure_authenticated()

request_url = self._url.joinpath(url[1:])
request_url = self._url.join(
URL(SplitResult("", "", url, "", ""), encoded=True)
)
headers = kwargs.get("headers") or self.headers
_LOGGER.debug("Request url: %s", request_url)
if not self._verify_ssl:
Expand Down Expand Up @@ -387,10 +389,9 @@ async def api_request_raw(
**kwargs: Any,
) -> bytes | None:
"""Make a request to UniFi Protect API"""
url = urljoin(self.api_path, url)
response = await self.request(
method,
url,
f"{self.api_path}{url}",
require_auth=require_auth,
auto_close=False,
**kwargs,
Expand Down Expand Up @@ -1542,7 +1543,7 @@ async def get_camera_video(

r = await self.request(
"get",
urljoin(self.api_path, path),
f"{self.api_path}{path}",
auto_close=False,
timeout=0,
params=params,
Expand Down

0 comments on commit a10fc5a

Please sign in to comment.