Skip to content

Commit 59135d8

Browse files
fix: add x-region support (#126)
1 parent 8db273a commit 59135d8

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

supabase_functions/_async/functions_client.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@ async def invoke(
6565
`responseType`: how the response should be parsed. The default is `json`
6666
"""
6767
headers = self.headers
68+
body = None
69+
response_type = "text/plain"
6870
if invoke_options is not None:
6971
headers.update(invoke_options.get("headers", {}))
72+
response_type = invoke_options.get("responseType", "text/plain")
7073

71-
body = invoke_options.get("body") if invoke_options else None
72-
response_type = (
73-
invoke_options.get("responseType") if invoke_options else "text/plain"
74-
)
74+
region = invoke_options.get("region")
75+
if region and isinstance(region, str) and region != "any":
76+
headers["x-region"] = region.lower().strip()
7577

76-
if type(body) == str:
77-
headers["Content-Type"] = "text/plain"
78-
elif type(body) == dict:
79-
headers["Content-Type"] = "application/json"
78+
body = invoke_options.get("body")
79+
if isinstance(body, str):
80+
headers["Content-Type"] = "text/plain"
81+
elif isinstance(body, dict):
82+
headers["Content-Type"] = "application/json"
8083

8184
response = await self._request(
8285
"POST", f"{self.url}/{function_name}", headers=headers, json=body

supabase_functions/_sync/functions_client.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@ def invoke(
6565
`responseType`: how the response should be parsed. The default is `json`
6666
"""
6767
headers = self.headers
68+
body = None
69+
response_type = "text/plain"
6870
if invoke_options is not None:
6971
headers.update(invoke_options.get("headers", {}))
72+
response_type = invoke_options.get("responseType", "text/plain")
7073

71-
body = invoke_options.get("body") if invoke_options else None
72-
response_type = (
73-
invoke_options.get("responseType") if invoke_options else "text/plain"
74-
)
74+
region = invoke_options.get("region")
75+
if region and isinstance(region, str) and region != "any":
76+
headers["x-region"] = region.lower().strip()
7577

76-
if type(body) == str:
77-
headers["Content-Type"] = "text/plain"
78-
elif type(body) == dict:
79-
headers["Content-Type"] = "application/json"
78+
body = invoke_options.get("body")
79+
if isinstance(body, str):
80+
headers["Content-Type"] = "text/plain"
81+
elif isinstance(body, dict):
82+
headers["Content-Type"] = "application/json"
8083

8184
response = self._request(
8285
"POST", f"{self.url}/{function_name}", headers=headers, json=body

0 commit comments

Comments
 (0)