Skip to content

Commit

Permalink
feat: Check if url is an HTTP URL (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Oct 31, 2024
1 parent 79d1979 commit eb7f319
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion postgrest/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions postgrest/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"}

0 comments on commit eb7f319

Please sign in to comment.