Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.
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
8 changes: 6 additions & 2 deletions supabase_functions/_async/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import HTTPError, Response

from ..errors import FunctionsHttpError, FunctionsRelayError
from ..utils import AsyncClient
from ..utils import AsyncClient, is_http_url, is_valid_str_arg
from ..version import __version__


Expand All @@ -16,6 +16,8 @@ def __init__(
verify: bool = True,
proxy: Optional[str] = None,
):
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
self.url = url
self.headers = {
"User-Agent": f"supabase-py/functions-py v{__version__}",
Expand All @@ -25,7 +27,7 @@ def __init__(
base_url=self.url,
headers=self.headers,
verify=bool(verify),
timeout=timeout,
timeout=int(abs(timeout)),
proxy=proxy,
follow_redirects=True,
http2=True,
Expand Down Expand Up @@ -73,6 +75,8 @@ async def invoke(
`body`: the body of the request
`responseType`: how the response should be parsed. The default is `json`
"""
if not is_valid_str_arg(function_name):
raise ValueError("function_name must a valid string value.")
headers = self.headers
body = None
response_type = "text/plain"
Expand Down
8 changes: 6 additions & 2 deletions supabase_functions/_sync/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import HTTPError, Response

from ..errors import FunctionsHttpError, FunctionsRelayError
from ..utils import SyncClient
from ..utils import SyncClient, is_http_url, is_valid_str_arg
from ..version import __version__


Expand All @@ -16,6 +16,8 @@ def __init__(
verify: bool = True,
proxy: Optional[str] = None,
):
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
self.url = url
self.headers = {
"User-Agent": f"supabase-py/functions-py v{__version__}",
Expand All @@ -25,7 +27,7 @@ def __init__(
base_url=self.url,
headers=self.headers,
verify=bool(verify),
timeout=timeout,
timeout=int(abs(timeout)),
proxy=proxy,
follow_redirects=True,
http2=True,
Expand Down Expand Up @@ -73,6 +75,8 @@ def invoke(
`body`: the body of the request
`responseType`: how the response should be parsed. The default is `json`
"""
if not is_valid_str_arg(function_name):
raise ValueError("function_name must a valid string value.")
headers = self.headers
body = None
response_type = "text/plain"
Expand Down
10 changes: 10 additions & 0 deletions supabase_functions/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import urlparse

from httpx import AsyncClient as AsyncClient # noqa: F401
from httpx import Client as BaseClient

Expand All @@ -7,3 +9,11 @@
class SyncClient(BaseClient):
def aclose(self) -> None:
self.close()


def is_valid_str_arg(target: str) -> bool:
return isinstance(target, str) and len(target.strip()) > 0


def is_http_url(url: str) -> bool:
return urlparse(url).scheme in {"https", "http"}