Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Check if url is an HTTP URL #526

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}