diff --git a/postgrest/base_client.py b/postgrest/base_client.py index 575080d..db6fffc 100644 --- a/postgrest/base_client.py +++ b/postgrest/base_client.py @@ -5,7 +5,7 @@ from httpx import BasicAuth, Timeout -from .utils import AsyncClient, SyncClient +from .utils import AsyncClient, SyncClient, is_http_url class BasePostgrestClient(ABC): @@ -21,6 +21,8 @@ def __init__( verify: bool = True, proxy: Optional[str] = None, ) -> None: + if not is_http_url(base_url): + ValueError("base_url must be a valid HTTP URL string") headers = { **headers, "Accept-Profile": schema, diff --git a/postgrest/utils.py b/postgrest/utils.py index 39dc1e2..31cda49 100644 --- a/postgrest/utils.py +++ b/postgrest/utils.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import Any, Type, TypeVar, cast, get_origin +from urllib.parse import urlparse from httpx import AsyncClient # noqa: F401 from httpx import Client as BaseClient # noqa: F401 @@ -35,3 +36,7 @@ def get_origin_and_cast(typ: type[type[_T]]) -> type[_T]: # See: definitions of request builders that use multiple-inheritance # like AsyncFilterRequestBuilder return cast(Type[_T], get_origin(typ)) + + +def is_http_url(url: str) -> bool: + return urlparse(url).scheme in {"https", "http"}