Skip to content

Commit eb7f319

Browse files
feat: Check if url is an HTTP URL (#526)
1 parent 79d1979 commit eb7f319

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

postgrest/base_client.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from httpx import BasicAuth, Timeout
77

8-
from .utils import AsyncClient, SyncClient
8+
from .utils import AsyncClient, SyncClient, is_http_url
99

1010

1111
class BasePostgrestClient(ABC):
@@ -21,6 +21,8 @@ def __init__(
2121
verify: bool = True,
2222
proxy: Optional[str] = None,
2323
) -> None:
24+
if not is_http_url(base_url):
25+
ValueError("base_url must be a valid HTTP URL string")
2426
headers = {
2527
**headers,
2628
"Accept-Profile": schema,

postgrest/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from typing import Any, Type, TypeVar, cast, get_origin
4+
from urllib.parse import urlparse
45

56
from httpx import AsyncClient # noqa: F401
67
from httpx import Client as BaseClient # noqa: F401
@@ -35,3 +36,7 @@ def get_origin_and_cast(typ: type[type[_T]]) -> type[_T]:
3536
# See: definitions of request builders that use multiple-inheritance
3637
# like AsyncFilterRequestBuilder
3738
return cast(Type[_T], get_origin(typ))
39+
40+
41+
def is_http_url(url: str) -> bool:
42+
return urlparse(url).scheme in {"https", "http"}

0 commit comments

Comments
 (0)