Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Add x-region support #126

Merged
merged 12 commits into from
Jul 25, 2024
19 changes: 11 additions & 8 deletions supabase_functions/_async/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ async def invoke(
`responseType`: how the response should be parsed. The default is `json`
"""
headers = self.headers
body = None
response_type = "text/plain"
if invoke_options is not None:
headers.update(invoke_options.get("headers", {}))
response_type = invoke_options.get("responseType", "text/plain")

body = invoke_options.get("body") if invoke_options else None
response_type = (
invoke_options.get("responseType") if invoke_options else "text/plain"
)
region = invoke_options.get("region")
if region and isinstance(region, str) and region != "any":
headers["x-region"] = region.lower().strip()

if type(body) == str:
headers["Content-Type"] = "text/plain"
elif type(body) == dict:
headers["Content-Type"] = "application/json"
body = invoke_options.get("body")
if isinstance(body, str):
headers["Content-Type"] = "text/plain"
elif isinstance(body, dict):
headers["Content-Type"] = "application/json"

response = await self._request(
"POST", f"{self.url}/{function_name}", headers=headers, json=body
Expand Down
19 changes: 11 additions & 8 deletions supabase_functions/_sync/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ def invoke(
`responseType`: how the response should be parsed. The default is `json`
"""
headers = self.headers
body = None
response_type = "text/plain"
if invoke_options is not None:
headers.update(invoke_options.get("headers", {}))
response_type = invoke_options.get("responseType", "text/plain")

body = invoke_options.get("body") if invoke_options else None
response_type = (
invoke_options.get("responseType") if invoke_options else "text/plain"
)
region = invoke_options.get("region")
if region and isinstance(region, str) and region != "any":
headers["x-region"] = region.lower().strip()

if type(body) == str:
headers["Content-Type"] = "text/plain"
elif type(body) == dict:
headers["Content-Type"] = "application/json"
body = invoke_options.get("body")
if isinstance(body, str):
headers["Content-Type"] = "text/plain"
elif isinstance(body, dict):
headers["Content-Type"] = "application/json"

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