Skip to content

Commit 6123554

Browse files
feat: Check if url is an HTTP URL (#156)
1 parent 1c17d79 commit 6123554

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

supabase_functions/_async/functions_client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from httpx import HTTPError, Response
44

55
from ..errors import FunctionsHttpError, FunctionsRelayError
6-
from ..utils import AsyncClient
6+
from ..utils import AsyncClient, is_http_url, is_valid_str_arg
77
from ..version import __version__
88

99

@@ -16,6 +16,8 @@ def __init__(
1616
verify: bool = True,
1717
proxy: Optional[str] = None,
1818
):
19+
if not is_http_url(url):
20+
ValueError("url must be a valid HTTP URL string")
1921
self.url = url
2022
self.headers = {
2123
"User-Agent": f"supabase-py/functions-py v{__version__}",
@@ -25,7 +27,7 @@ def __init__(
2527
base_url=self.url,
2628
headers=self.headers,
2729
verify=bool(verify),
28-
timeout=timeout,
30+
timeout=int(abs(timeout)),
2931
proxy=proxy,
3032
follow_redirects=True,
3133
http2=True,
@@ -73,6 +75,8 @@ async def invoke(
7375
`body`: the body of the request
7476
`responseType`: how the response should be parsed. The default is `json`
7577
"""
78+
if not is_valid_str_arg(function_name):
79+
raise ValueError("function_name must a valid string value.")
7680
headers = self.headers
7781
body = None
7882
response_type = "text/plain"

supabase_functions/_sync/functions_client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from httpx import HTTPError, Response
44

55
from ..errors import FunctionsHttpError, FunctionsRelayError
6-
from ..utils import SyncClient
6+
from ..utils import SyncClient, is_http_url, is_valid_str_arg
77
from ..version import __version__
88

99

@@ -16,6 +16,8 @@ def __init__(
1616
verify: bool = True,
1717
proxy: Optional[str] = None,
1818
):
19+
if not is_http_url(url):
20+
ValueError("url must be a valid HTTP URL string")
1921
self.url = url
2022
self.headers = {
2123
"User-Agent": f"supabase-py/functions-py v{__version__}",
@@ -25,7 +27,7 @@ def __init__(
2527
base_url=self.url,
2628
headers=self.headers,
2729
verify=bool(verify),
28-
timeout=timeout,
30+
timeout=int(abs(timeout)),
2931
proxy=proxy,
3032
follow_redirects=True,
3133
http2=True,
@@ -73,6 +75,8 @@ def invoke(
7375
`body`: the body of the request
7476
`responseType`: how the response should be parsed. The default is `json`
7577
"""
78+
if not is_valid_str_arg(function_name):
79+
raise ValueError("function_name must a valid string value.")
7680
headers = self.headers
7781
body = None
7882
response_type = "text/plain"

supabase_functions/utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urllib.parse import urlparse
2+
13
from httpx import AsyncClient as AsyncClient # noqa: F401
24
from httpx import Client as BaseClient
35

@@ -7,3 +9,11 @@
79
class SyncClient(BaseClient):
810
def aclose(self) -> None:
911
self.close()
12+
13+
14+
def is_valid_str_arg(target: str) -> bool:
15+
return isinstance(target, str) and len(target.strip()) > 0
16+
17+
18+
def is_http_url(url: str) -> bool:
19+
return urlparse(url).scheme in {"https", "http"}

0 commit comments

Comments
 (0)