Add general solutions for URLs.

This commit is contained in:
Alejandro Cabeza Romero 2025-12-19 12:54:26 +01:00
parent 0fd630d6a4
commit cafc518860
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD

View File

@ -1,6 +1,6 @@
import logging import logging
from typing import TYPE_CHECKING, AsyncIterator, List, Optional from typing import TYPE_CHECKING, AsyncIterator, List, Optional
from urllib.parse import urljoin from urllib.parse import urljoin, urlunparse
import httpx import httpx
from pydantic import ValidationError from pydantic import ValidationError
@ -35,8 +35,27 @@ class HttpNodeApi(NodeApi):
) )
@property @property
def base_url(self): def base_url(self) -> str:
return f"{self.protocol}://{self.host}:{self.port}" if "/" in self.host:
host, path = self.host.split("/", 1)
path = "/" + path
else:
host = self.host
path = ""
network_location = f"{host}:{self.port}" if self.port else host
return urlunparse(
(
self.protocol,
network_location,
path,
# The following are unused but required
"", # Params
"", # Query
"", # Fragment
)
)
async def get_health(self) -> HealthSerializer: async def get_health(self) -> HealthSerializer:
url = urljoin(self.base_url, self.ENDPOINT_INFO) url = urljoin(self.base_url, self.ENDPOINT_INFO)