Skip to content

Add x-region support #126

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

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